library(tswge)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
## 
## Attaching package: 'tswge'
## The following object is masked from 'package:datasets':
## 
##     uspop
library(vars)
## Warning: package 'vars' was built under R version 4.3.1
## Loading required package: MASS
## 
## Attaching package: 'MASS'
## The following object is masked from 'package:tswge':
## 
##     cement
## Loading required package: strucchange
## Warning: package 'strucchange' was built under R version 4.3.1
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
## Loading required package: sandwich
## Warning: package 'sandwich' was built under R version 4.3.1
## Loading required package: urca
## Loading required package: lmtest
## 
## Attaching package: 'lmtest'
## The following object is masked from 'package:tswge':
## 
##     wages
library(nnfor)
## Loading required package: generics
## 
## Attaching package: 'generics'
## The following object is masked from 'package:sandwich':
## 
##     estfun
## The following objects are masked from 'package:base':
## 
##     as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
##     setequal, union
library(fpp)
## Warning: package 'fpp' was built under R version 4.3.1
## Loading required package: forecast
## Loading required package: fma
## 
## Attaching package: 'fma'
## The following objects are masked from 'package:MASS':
## 
##     cement, housing, petrol
## The following object is masked from 'package:tswge':
## 
##     cement
## Loading required package: expsmooth
## 
## Attaching package: 'expsmooth'
## The following object is masked from 'package:tswge':
## 
##     freight
## Loading required package: tseries
library(forecast)
library(backtest)
## Warning: package 'backtest' was built under R version 4.3.1
## Loading required package: grid
## Loading required package: lattice
library(quantmod)
## Loading required package: xts
## Loading required package: TTR
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(dplyr)
## 
## ######################### Warning from 'xts' package ##########################
## #                                                                             #
## # The dplyr lag() function breaks how base R's lag() function is supposed to  #
## # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
## # source() into this session won't work correctly.                            #
## #                                                                             #
## # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
## # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
## # dplyr from breaking base R's lag() function.                                #
## #                                                                             #
## # Code in packages is not affected. It's protected by R's namespace mechanism #
## # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
## #                                                                             #
## ###############################################################################
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:xts':
## 
##     first, last
## The following object is masked from 'package:generics':
## 
##     explain
## The following object is masked from 'package:MASS':
## 
##     select
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(astsa)
## 
## Attaching package: 'astsa'
## The following object is masked from 'package:fpp':
## 
##     oil
## The following objects are masked from 'package:fma':
## 
##     chicken, sales
## The following object is masked from 'package:forecast':
## 
##     gas
## The following object is masked from 'package:tswge':
## 
##     flu
library(GGally)
## Warning: package 'GGally' was built under R version 4.3.1
## Loading required package: ggplot2
## Registered S3 method overwritten by 'GGally':
##   method from   
##   +.gg   ggplot2
## 
## Attaching package: 'GGally'
## The following object is masked from 'package:fma':
## 
##     pigs
library(zoo)
library(tidyr)

Background

Our client Annaly Capital Management, Inc. is one of the largest mortgage real estate investment trusts. It is organized in Maryland with its principal office in New York City. The company borrows money, primarily via short term repurchase agreements, and reinvests the proceeds in asset-backed securities. CEO: David L. Finkelstein (Mar 2020–) has hired our firm to examine its past historical data and perform several time series forecasts to predict where the stock will open in the future based on current volumes. The data is contains the open, close, high, low price as well as the total volume recorded at every seven day period between the period 2013 - 2018.

We were asked for supplemental analysis coming from the consumer price index and mortgage rates for the period examined to see if these supplemental explanatory variable will have an effect on modeling.

Load in the data from github

df = read.csv("https://raw.githubusercontent.com/ReuvenDerner/MSDS-6373-Time-Series/master/Unit%205/NLY.csv")

cpi = read.csv("https://raw.githubusercontent.com/ReuvenDerner/TimeSeriesProject2023/main/CPI_CSV_2013_2018.xlsx%20-%20Sheet1.csv")

mort = read.csv("https://raw.githubusercontent.com/ReuvenDerner/TimeSeriesProject2023/main/MORTGAGE30US_2013_2018.csv")
# take a sample of 15 from the dataframe
nyse_sample = sample_n(df, 5)
knitr::kable(nyse_sample, "html")
Date Open High Low Close Adj.Close Volume
10/19/15 10.14 10.28 10.11 10.18 7.296029 27311100
3/27/17 11.14 11.37 11.02 11.11 9.213124 41196600
9/7/15 10.2 10.25 9.92 10.09 7.023324 28987400
4/11/16 10.16 10.45 10.16 10.41 7.926142 67314400
5/2/16 10.43 10.85 10.25 10.85 8.261157 48933200
cpi_sample = sample_n(cpi, 5)
knitr::kable(cpi_sample, "html")
Year Month CPI_Score
2018 Jan 247.867
2016 Mar 238.132
2018 Aug 252.146
2018 May 251.588
2017 Jun 244.955
mort_sample = sample_n(mort, 5)
knitr::kable(mort_sample, "html")
DATE MORTGAGE30US
2014-07-17 4.13
2017-09-28 3.83
2018-08-09 4.59
2016-05-05 3.61
2018-11-15 4.94

The data has no missing values and no imputation is necessary, we can proceed with our analysis.

#reassign the dataframe 
#df = TimeSeriesProject2018_2020

# Address the missing values in each column (NA as well as empty strings).
missing_df = as.data.frame(sapply(df, function(x) sum(is.na(x))))
colnames(missing_df) = c("variable missing")
knitr::kable(missing_df, "html")
variable missing
Date 0
Open 0
High 0
Low 0
Close 0
Adj.Close 0
Volume 0
empty_string_df = as.data.frame(sapply(df, function(x) sum(x == "")))
colnames(empty_string_df) = c("variable empty")
knitr::kable(empty_string_df, "html")
variable empty
Date 0
Open 0
High 0
Low 0
Close 0
Adj.Close 0
Volume 0

Generate summary statistics

# Generate summary statistics
summary(df)
##      Date               Open               High               Low           
##  Length:263         Length:263         Length:263         Length:263        
##  Class :character   Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character   Mode  :character  
##     Close            Adj.Close            Volume         
##  Length:263         Length:263         Length:263        
##  Class :character   Class :character   Class :character  
##  Mode  :character   Mode  :character   Mode  :character
summary(cpi)
##       Year         Month             CPI_Score    
##  Min.   :2013   Length:72          Min.   :230.3  
##  1st Qu.:2014   Class :character   1st Qu.:236.3  
##  Median :2016   Mode  :character   Median :238.3  
##  Mean   :2016                      Mean   :240.6  
##  3rd Qu.:2017                      3rd Qu.:244.8  
##  Max.   :2018                      Max.   :252.9
summary(mort)
##      DATE            MORTGAGE30US  
##  Length:263         Min.   :3.410  
##  Class :character   1st Qu.:3.815  
##  Mode  :character   Median :3.990  
##                     Mean   :4.039  
##                     3rd Qu.:4.280  
##                     Max.   :4.940

We need to reclassify the data as numeric volumes, in addition we will have to adjust our input data from mortgage & consumer price index rates as additional columns in the data frame.

# Convert the Date column with the correct format
df$Date <- as.Date(df$Date, format = "%m/%d/%y")

# Convert columns to appropriate data types
df <- df %>%
  mutate(Date = as.Date(Date),            # Convert Date column to Date type
         Open = as.numeric(Open),         # Convert Open column to numeric type
         High = as.numeric(High),         # Convert High column to numeric type
         Low = as.numeric(Low),           # Convert Low column to numeric type
         Close = as.numeric(Close),       # Convert Close column to numeric type
         Adj.Close = as.numeric(Adj.Close),  # Convert Adj Close column to numeric type
         Volume = as.integer(Volume))     # Convert Volume column to integer type
## Warning: There were 6 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `Open = as.numeric(Open)`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 5 remaining warnings.
summary(df)
##       Date                 Open            High            Low       
##  Min.   :2013-11-18   Min.   : 8.97   Min.   : 9.04   Min.   : 8.25  
##  1st Qu.:2015-02-19   1st Qu.:10.21   1st Qu.:10.36   1st Qu.:10.03  
##  Median :2016-05-23   Median :10.59   Median :10.74   Median :10.40  
##  Mean   :2016-05-22   Mean   :10.75   Mean   :10.91   Mean   :10.57  
##  3rd Qu.:2017-08-24   3rd Qu.:11.31   3rd Qu.:11.49   3rd Qu.:11.15  
##  Max.   :2018-11-23   Max.   :12.61   Max.   :12.73   Max.   :12.32  
##                       NA's   :1       NA's   :1       NA's   :1      
##      Close         Adj.Close          Volume         
##  Min.   : 8.96   Min.   : 5.572   Min.   :  4209958  
##  1st Qu.:10.21   1st Qu.: 7.000   1st Qu.: 33175550  
##  Median :10.57   Median : 8.060   Median : 40010450  
##  Mean   :10.75   Mean   : 8.291   Mean   : 43003015  
##  3rd Qu.:11.31   3rd Qu.: 9.854   3rd Qu.: 49882100  
##  Max.   :12.60   Max.   :10.994   Max.   :197494800  
##  NA's   :1       NA's   :1        NA's   :1

NA were introduced by the mutation of the data, we will just remove the record where that occurs

df.adj = na.omit(df)

Next lets examine CPI and MORT rates

cpi = read.csv("https://raw.githubusercontent.com/ReuvenDerner/TimeSeriesProject2023/main/CPI_CSV_2013_2018.xlsx%20-%20Sheet1.csv")


# Step 1: Create a new "Date" column in the "cpi" dataset by combining "Year" and "Month"
cpi$Date <- as.Date(paste(cpi$Year, cpi$Month, "01", sep = "-"), format = "%Y-%b-%d")

# Step 2: Select only the "Year", "Month", and "CPI_Score" columns from the "cpi" dataset
cpi <- cpi %>%
  select(Year, Month, CPI_Score)

# Step 3: Extract "Year" and "Month" from the "df" Date column
df$Year <- format(df$Date, "%Y")
df$Month <- format(df$Date, "%b")


# Step 3: Convert "Year" column in "df" to integer
df$Year <- as.integer(df$Year)

# Step 4: Merge "df" and "cpi" datasets based on "Year" and "Month"
final_data <- df %>%
  left_join(cpi, by = c("Year", "Month"))

# Step 5: Forward fill (carry the last observation forward) the "CPI_Score" values to fill missing values
final_data <- final_data %>%
  group_by(Year) %>%
  tidyr::fill(CPI_Score, .direction = "downup") %>%
  ungroup()

#display final column to see output
head(final_data,10)
## # A tibble: 10 × 10
##    Date        Open  High   Low Close Adj.Close    Volume  Year Month CPI_Score
##    <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>     <int> <int> <chr>     <dbl>
##  1 2013-11-18 NA     NA   NA    NA        NA           NA  2013 Nov        233.
##  2 2013-11-25 10.2   10.3  9.86 10.2       5.81  77369900  2013 Nov        233.
##  3 2013-12-02 10.2   10.2  9.66  9.74      5.57  73844200  2013 Dec        233.
##  4 2013-12-09  9.7   10.3  9.69  9.94      5.69  65017500  2013 Dec        233.
##  5 2013-12-16  9.94  10.4  9.79 10.1       5.78 108105500  2013 Dec        233.
##  6 2013-12-23 10.1   10.3  9.81  9.83      5.62  52552600  2013 Dec        233.
##  7 2013-12-30  9.82  10.1  9.72 10         5.90  65043600  2013 Dec        233.
##  8 2014-01-06 10.0   10.3  9.97 10.2       6.04  63756100  2014 Jan        234.
##  9 2014-01-13 10.2   10.4 10.1  10.2       6.01  42784400  2014 Jan        234.
## 10 2014-01-20 10.2   10.7 10.2  10.5       6.21  42342100  2014 Jan        234.
final_data2 = final_data
# Step 1: Convert the "DATE" column in mort to Date type
mort$DATE <- as.Date(mort$DATE)

# Step 2: Use approx() to find the closest "MORTGAGE30US" rate for each DATE in final_data
nearest_mortgage <- approx(mort$DATE, mort$MORTGAGE30US, final_data2$Date)$y

# Step 3: Add the "MORTGAGE30US" rate to the final_data dataset
final_data2$MORTGAGE30US <- nearest_mortgage

# Now, "final_data" contains the combined dataset with "CPI_Score" and "MORTGAGE30US" rates for each date.

head(final_data2)
## # A tibble: 6 × 11
##   Date        Open  High   Low Close Adj.Close    Volume  Year Month CPI_Score
##   <date>     <dbl> <dbl> <dbl> <dbl>     <dbl>     <int> <int> <chr>     <dbl>
## 1 2013-11-18 NA     NA   NA    NA        NA           NA  2013 Nov        233.
## 2 2013-11-25 10.2   10.3  9.86 10.2       5.81  77369900  2013 Nov        233.
## 3 2013-12-02 10.2   10.2  9.66  9.74      5.57  73844200  2013 Dec        233.
## 4 2013-12-09  9.7   10.3  9.69  9.94      5.69  65017500  2013 Dec        233.
## 5 2013-12-16  9.94  10.4  9.79 10.1       5.78 108105500  2013 Dec        233.
## 6 2013-12-23 10.1   10.3  9.81  9.83      5.62  52552600  2013 Dec        233.
## # ℹ 1 more variable: MORTGAGE30US <dbl>
# Remove the columns "Year", and "Month" from the "final_data" dataframe
final_data2 <- final_data2 %>%
  select(-Year, -Month)

#rename dataframe for use in modeling
finaldata <- na.omit(final_data2)

There was two data points that had missing data contained within them. We removed these records from the data set to be used in modeling.

Examine any correlations that may exist

ggpairs(df.adj)

ggpairs(finaldata)

The adj.Close & Open Price is significantly correlated to all other variables in the dataset, particular with one another at 0.91 positive correlation.

The CPI_Score does have a very strong correlation to Date (time) and Adj.Close price. This makes sense given that the CPI score is regulated and reevaluated by the FED every month. In addition the overall average mortgage rate has a moderate positive correlation to CPI Score, as rates tend to rise, the overall consumer price also rises.

Check some data based on our response variable “Open”

## $xbar
## [1] 10.74882
## 
## $autplt
##  [1] 1.0000000 0.9558782 0.9140551 0.8798739 0.8356028 0.7947093 0.7579893
##  [8] 0.7244069 0.6985809 0.6709464 0.6492885 0.6188956 0.5877319 0.5641738
## [15] 0.5247691 0.4840137 0.4481811 0.4072040 0.3655794 0.3241797 0.2839057
## [22] 0.2530625 0.2206851 0.2007074 0.1831944 0.1594867
## 
## $freq
##   [1] 0.003816794 0.007633588 0.011450382 0.015267176 0.019083969 0.022900763
##   [7] 0.026717557 0.030534351 0.034351145 0.038167939 0.041984733 0.045801527
##  [13] 0.049618321 0.053435115 0.057251908 0.061068702 0.064885496 0.068702290
##  [19] 0.072519084 0.076335878 0.080152672 0.083969466 0.087786260 0.091603053
##  [25] 0.095419847 0.099236641 0.103053435 0.106870229 0.110687023 0.114503817
##  [31] 0.118320611 0.122137405 0.125954198 0.129770992 0.133587786 0.137404580
##  [37] 0.141221374 0.145038168 0.148854962 0.152671756 0.156488550 0.160305344
##  [43] 0.164122137 0.167938931 0.171755725 0.175572519 0.179389313 0.183206107
##  [49] 0.187022901 0.190839695 0.194656489 0.198473282 0.202290076 0.206106870
##  [55] 0.209923664 0.213740458 0.217557252 0.221374046 0.225190840 0.229007634
##  [61] 0.232824427 0.236641221 0.240458015 0.244274809 0.248091603 0.251908397
##  [67] 0.255725191 0.259541985 0.263358779 0.267175573 0.270992366 0.274809160
##  [73] 0.278625954 0.282442748 0.286259542 0.290076336 0.293893130 0.297709924
##  [79] 0.301526718 0.305343511 0.309160305 0.312977099 0.316793893 0.320610687
##  [85] 0.324427481 0.328244275 0.332061069 0.335877863 0.339694656 0.343511450
##  [91] 0.347328244 0.351145038 0.354961832 0.358778626 0.362595420 0.366412214
##  [97] 0.370229008 0.374045802 0.377862595 0.381679389 0.385496183 0.389312977
## [103] 0.393129771 0.396946565 0.400763359 0.404580153 0.408396947 0.412213740
## [109] 0.416030534 0.419847328 0.423664122 0.427480916 0.431297710 0.435114504
## [115] 0.438931298 0.442748092 0.446564885 0.450381679 0.454198473 0.458015267
## [121] 0.461832061 0.465648855 0.469465649 0.473282443 0.477099237 0.480916031
## [127] 0.484732824 0.488549618 0.492366412 0.496183206 0.500000000
## 
## $dbz
##   [1]  12.3443460  12.1228799  11.7532303  11.2347782  10.5671017   9.7505942
##   [7]   8.7875642   7.6841519   6.4535662   5.1212070   3.7316979   2.3555051
##  [13]   1.0875438   0.0259685  -0.7692079  -1.3080599  -1.6600405  -1.9129555
##  [19]  -2.1400160  -2.3896794  -2.6893036  -3.0518240  -3.4806765  -3.9722487
##  [25]  -4.5166737  -5.0981771  -5.6962174  -6.2883607  -6.8549197  -7.3838797
##  [31]  -7.8735208  -8.3307927  -8.7658815  -9.1855952  -9.5886185  -9.9647212
##  [37] -10.2985759 -10.5770289 -10.7965340 -10.9665692 -11.1069589 -11.2408671
##  [43] -11.3872726 -11.5557692 -11.7445346 -11.9411914 -12.1261441 -12.2778885
##  [49] -12.3791413 -12.4217684 -12.4085394 -12.3512550 -12.2667084 -12.1726483
##  [55] -12.0851369 -12.0174958 -11.9802959 -11.9817327 -12.0279214 -12.1228943
##  [61] -12.2682448 -12.4624343 -12.6998127 -12.9694599 -13.2541297 -13.5299047
##  [67] -13.7675699 -13.9367607 -14.0129350 -13.9850215 -13.8598244 -13.6604049
##  [73] -13.4194473 -13.1714081 -12.9467196 -12.7690074 -12.6545893 -12.6131227
##  [79] -12.6485770 -12.7601240 -12.9428284 -13.1881519 -13.4843191 -13.8165558
##  [85] -14.1671642 -14.5154049 -14.8373456 -15.1062620 -15.2946569 -15.3788765
##  [91] -15.3458703 -15.1992467 -14.9607755 -14.6658854 -14.3556431 -14.0692508
##  [97] -13.8394649 -13.6909797 -13.6406322 -13.6982675 -13.8675239 -14.1461975
## [103] -14.5261126 -14.9926349 -15.5242113 -16.0926253 -16.6648862 -17.2073897
## [109] -17.6917666 -18.1000522 -18.4261423 -18.6724033 -18.8435710 -18.9417729
## [115] -18.9654783 -18.9126401 -18.7858615 -18.5962859 -18.3638336 -18.1138551
## [121] -17.8722552 -17.6612698 -17.4968983 -17.3878545 -17.3354561 -17.3339992
## [127] -17.3715141 -17.4311300 -17.4934183 -17.5398684 -17.5570033

## $freq
##   [1] 0.003816794 0.007633588 0.011450382 0.015267176 0.019083969 0.022900763
##   [7] 0.026717557 0.030534351 0.034351145 0.038167939 0.041984733 0.045801527
##  [13] 0.049618321 0.053435115 0.057251908 0.061068702 0.064885496 0.068702290
##  [19] 0.072519084 0.076335878 0.080152672 0.083969466 0.087786260 0.091603053
##  [25] 0.095419847 0.099236641 0.103053435 0.106870229 0.110687023 0.114503817
##  [31] 0.118320611 0.122137405 0.125954198 0.129770992 0.133587786 0.137404580
##  [37] 0.141221374 0.145038168 0.148854962 0.152671756 0.156488550 0.160305344
##  [43] 0.164122137 0.167938931 0.171755725 0.175572519 0.179389313 0.183206107
##  [49] 0.187022901 0.190839695 0.194656489 0.198473282 0.202290076 0.206106870
##  [55] 0.209923664 0.213740458 0.217557252 0.221374046 0.225190840 0.229007634
##  [61] 0.232824427 0.236641221 0.240458015 0.244274809 0.248091603 0.251908397
##  [67] 0.255725191 0.259541985 0.263358779 0.267175573 0.270992366 0.274809160
##  [73] 0.278625954 0.282442748 0.286259542 0.290076336 0.293893130 0.297709924
##  [79] 0.301526718 0.305343511 0.309160305 0.312977099 0.316793893 0.320610687
##  [85] 0.324427481 0.328244275 0.332061069 0.335877863 0.339694656 0.343511450
##  [91] 0.347328244 0.351145038 0.354961832 0.358778626 0.362595420 0.366412214
##  [97] 0.370229008 0.374045802 0.377862595 0.381679389 0.385496183 0.389312977
## [103] 0.393129771 0.396946565 0.400763359 0.404580153 0.408396947 0.412213740
## [109] 0.416030534 0.419847328 0.423664122 0.427480916 0.431297710 0.435114504
## [115] 0.438931298 0.442748092 0.446564885 0.450381679 0.454198473 0.458015267
## [121] 0.461832061 0.465648855 0.469465649 0.473282443 0.477099237 0.480916031
## [127] 0.484732824 0.488549618 0.492366412 0.496183206 0.500000000
## 
## $pzgram
##   [1]  12.3443460  12.1228799  11.7532303  11.2347782  10.5671017   9.7505942
##   [7]   8.7875642   7.6841519   6.4535662   5.1212070   3.7316979   2.3555051
##  [13]   1.0875438   0.0259685  -0.7692079  -1.3080599  -1.6600405  -1.9129555
##  [19]  -2.1400160  -2.3896794  -2.6893036  -3.0518240  -3.4806765  -3.9722487
##  [25]  -4.5166737  -5.0981771  -5.6962174  -6.2883607  -6.8549197  -7.3838797
##  [31]  -7.8735208  -8.3307927  -8.7658815  -9.1855952  -9.5886185  -9.9647212
##  [37] -10.2985759 -10.5770289 -10.7965340 -10.9665692 -11.1069589 -11.2408671
##  [43] -11.3872726 -11.5557692 -11.7445346 -11.9411914 -12.1261441 -12.2778885
##  [49] -12.3791413 -12.4217684 -12.4085394 -12.3512550 -12.2667084 -12.1726483
##  [55] -12.0851369 -12.0174958 -11.9802959 -11.9817327 -12.0279214 -12.1228943
##  [61] -12.2682448 -12.4624343 -12.6998127 -12.9694599 -13.2541297 -13.5299047
##  [67] -13.7675699 -13.9367607 -14.0129350 -13.9850215 -13.8598244 -13.6604049
##  [73] -13.4194473 -13.1714081 -12.9467196 -12.7690074 -12.6545893 -12.6131227
##  [79] -12.6485770 -12.7601240 -12.9428284 -13.1881519 -13.4843191 -13.8165558
##  [85] -14.1671642 -14.5154049 -14.8373456 -15.1062620 -15.2946569 -15.3788765
##  [91] -15.3458703 -15.1992467 -14.9607755 -14.6658854 -14.3556431 -14.0692508
##  [97] -13.8394649 -13.6909797 -13.6406322 -13.6982675 -13.8675239 -14.1461975
## [103] -14.5261126 -14.9926349 -15.5242113 -16.0926253 -16.6648862 -17.2073897
## [109] -17.6917666 -18.1000522 -18.4261423 -18.6724033 -18.8435710 -18.9417729
## [115] -18.9654783 -18.9126401 -18.7858615 -18.5962859 -18.3638336 -18.1138551
## [121] -17.8722552 -17.6612698 -17.4968983 -17.3878545 -17.3354561 -17.3339992
## [127] -17.3715141 -17.4311300 -17.4934183 -17.5398684 -17.5570033

## $xbar
## [1] 10.75188
## 
## $autplt
##  [1] 1.0000000 0.9558761 0.9140608 0.8783026 0.8343831 0.7937568 0.7564875
##  [8] 0.7238239 0.6984386 0.6712387 0.6491151 0.6204025 0.5894214 0.5655573
## [15] 0.5263501 0.4840331 0.4487245 0.4077411 0.3654875 0.3235514 0.2837316
## [22] 0.2515254 0.2207263 0.1998491 0.1826889 0.1586367
## 
## $freq
##   [1] 0.003831418 0.007662835 0.011494253 0.015325670 0.019157088 0.022988506
##   [7] 0.026819923 0.030651341 0.034482759 0.038314176 0.042145594 0.045977011
##  [13] 0.049808429 0.053639847 0.057471264 0.061302682 0.065134100 0.068965517
##  [19] 0.072796935 0.076628352 0.080459770 0.084291188 0.088122605 0.091954023
##  [25] 0.095785441 0.099616858 0.103448276 0.107279693 0.111111111 0.114942529
##  [31] 0.118773946 0.122605364 0.126436782 0.130268199 0.134099617 0.137931034
##  [37] 0.141762452 0.145593870 0.149425287 0.153256705 0.157088123 0.160919540
##  [43] 0.164750958 0.168582375 0.172413793 0.176245211 0.180076628 0.183908046
##  [49] 0.187739464 0.191570881 0.195402299 0.199233716 0.203065134 0.206896552
##  [55] 0.210727969 0.214559387 0.218390805 0.222222222 0.226053640 0.229885057
##  [61] 0.233716475 0.237547893 0.241379310 0.245210728 0.249042146 0.252873563
##  [67] 0.256704981 0.260536398 0.264367816 0.268199234 0.272030651 0.275862069
##  [73] 0.279693487 0.283524904 0.287356322 0.291187739 0.295019157 0.298850575
##  [79] 0.302681992 0.306513410 0.310344828 0.314176245 0.318007663 0.321839080
##  [85] 0.325670498 0.329501916 0.333333333 0.337164751 0.340996169 0.344827586
##  [91] 0.348659004 0.352490421 0.356321839 0.360153257 0.363984674 0.367816092
##  [97] 0.371647510 0.375478927 0.379310345 0.383141762 0.386973180 0.390804598
## [103] 0.394636015 0.398467433 0.402298851 0.406130268 0.409961686 0.413793103
## [109] 0.417624521 0.421455939 0.425287356 0.429118774 0.432950192 0.436781609
## [115] 0.440613027 0.444444444 0.448275862 0.452107280 0.455938697 0.459770115
## [121] 0.463601533 0.467432950 0.471264368 0.475095785 0.478927203 0.482758621
## [127] 0.486590038 0.490421456 0.494252874 0.498084291
## 
## $dbz
##   [1]  12.34247354  12.11914326  11.74635018  11.22342293  10.54987428
##   [6]   9.72603461   8.75418736   7.64056246   6.39872676   5.05498450
##  [11]   3.65581433   2.27479289   1.01067362  -0.03604101  -0.80727694
##  [16]  -1.31903982  -1.64675193  -1.88122193  -2.09593187  -2.33839785
##  [21]  -2.63486737  -2.99735762  -3.42858191  -3.92430375  -4.47404643
##  [26]  -5.06141232  -5.66526486  -6.26269996  -6.83377528  -7.36642486
##  [31]  -7.85890296  -8.31787269  -8.75274349  -9.16904719  -9.56399873
##  [36]  -9.92632939 -10.24088770 -10.49642769 -10.69279641 -10.84330773
##  [41] -10.97088671 -11.10048445 -11.25169391 -11.43398966 -11.64498097
##  [46] -11.87120849 -12.09114324 -12.28018512 -12.41691364 -12.48879033
##  [51] -12.49507403 -12.44586320 -12.35826980 -12.25194835 -12.14575162
##  [56] -12.05602858 -11.99615702 -11.97665194 -12.00534780 -12.08739385
##  [61] -12.22496696 -12.41668031 -12.65669968 -12.93364814 -13.22956668
##  [66] -13.51955972 -13.77319751 -13.95882941 -14.05091009 -14.03806607
##  [71] -13.92769631 -13.74414594 -13.52160997 -13.29588031 -13.09837508
##  [76] -12.95336172 -12.87751581 -12.88058643 -12.96629340 -13.13302503
##  [81] -13.37420317 -13.67834022 -14.02889961 -14.40414854 -14.77730940
##  [86] -15.11749541 -15.39208435 -15.57106927 -15.63311292 -15.57151749
##  [91] -15.39722851 -15.13692019 -14.82696395 -14.50622252 -14.21040074
##  [96] -13.96897449 -13.80426228 -13.73169224 -13.76044971 -13.89400346
## [101] -14.13027252 -14.46138142 -14.87311844 -15.34443090 -15.84758554
## [106] -16.34986662 -16.81750858 -17.22153106 -17.54346560 -17.77806885
## [111] -17.93148745 -18.01620729 -18.04583417 -18.03203751 -17.98407988
## [116] -17.90993918 -17.81767355 -17.71608913 -17.61445144 -17.52152841
## [121] -17.44446679 -17.38791989 -17.35363279 -17.34050359 -17.34503321
## [126] -17.36203822 -17.38549708 -17.40940880 -17.42856219 -17.43914307

## $freq
##   [1] 0.003831418 0.007662835 0.011494253 0.015325670 0.019157088 0.022988506
##   [7] 0.026819923 0.030651341 0.034482759 0.038314176 0.042145594 0.045977011
##  [13] 0.049808429 0.053639847 0.057471264 0.061302682 0.065134100 0.068965517
##  [19] 0.072796935 0.076628352 0.080459770 0.084291188 0.088122605 0.091954023
##  [25] 0.095785441 0.099616858 0.103448276 0.107279693 0.111111111 0.114942529
##  [31] 0.118773946 0.122605364 0.126436782 0.130268199 0.134099617 0.137931034
##  [37] 0.141762452 0.145593870 0.149425287 0.153256705 0.157088123 0.160919540
##  [43] 0.164750958 0.168582375 0.172413793 0.176245211 0.180076628 0.183908046
##  [49] 0.187739464 0.191570881 0.195402299 0.199233716 0.203065134 0.206896552
##  [55] 0.210727969 0.214559387 0.218390805 0.222222222 0.226053640 0.229885057
##  [61] 0.233716475 0.237547893 0.241379310 0.245210728 0.249042146 0.252873563
##  [67] 0.256704981 0.260536398 0.264367816 0.268199234 0.272030651 0.275862069
##  [73] 0.279693487 0.283524904 0.287356322 0.291187739 0.295019157 0.298850575
##  [79] 0.302681992 0.306513410 0.310344828 0.314176245 0.318007663 0.321839080
##  [85] 0.325670498 0.329501916 0.333333333 0.337164751 0.340996169 0.344827586
##  [91] 0.348659004 0.352490421 0.356321839 0.360153257 0.363984674 0.367816092
##  [97] 0.371647510 0.375478927 0.379310345 0.383141762 0.386973180 0.390804598
## [103] 0.394636015 0.398467433 0.402298851 0.406130268 0.409961686 0.413793103
## [109] 0.417624521 0.421455939 0.425287356 0.429118774 0.432950192 0.436781609
## [115] 0.440613027 0.444444444 0.448275862 0.452107280 0.455938697 0.459770115
## [121] 0.463601533 0.467432950 0.471264368 0.475095785 0.478927203 0.482758621
## [127] 0.486590038 0.490421456 0.494252874 0.498084291
## 
## $pzgram
##   [1]  12.34247354  12.11914326  11.74635018  11.22342293  10.54987428
##   [6]   9.72603461   8.75418736   7.64056246   6.39872676   5.05498450
##  [11]   3.65581433   2.27479289   1.01067362  -0.03604101  -0.80727694
##  [16]  -1.31903982  -1.64675193  -1.88122193  -2.09593187  -2.33839785
##  [21]  -2.63486737  -2.99735762  -3.42858191  -3.92430375  -4.47404643
##  [26]  -5.06141232  -5.66526486  -6.26269996  -6.83377528  -7.36642486
##  [31]  -7.85890296  -8.31787269  -8.75274349  -9.16904719  -9.56399873
##  [36]  -9.92632939 -10.24088770 -10.49642769 -10.69279641 -10.84330773
##  [41] -10.97088671 -11.10048445 -11.25169391 -11.43398966 -11.64498097
##  [46] -11.87120849 -12.09114324 -12.28018512 -12.41691364 -12.48879033
##  [51] -12.49507403 -12.44586320 -12.35826980 -12.25194835 -12.14575162
##  [56] -12.05602858 -11.99615702 -11.97665194 -12.00534780 -12.08739385
##  [61] -12.22496696 -12.41668031 -12.65669968 -12.93364814 -13.22956668
##  [66] -13.51955972 -13.77319751 -13.95882941 -14.05091009 -14.03806607
##  [71] -13.92769631 -13.74414594 -13.52160997 -13.29588031 -13.09837508
##  [76] -12.95336172 -12.87751581 -12.88058643 -12.96629340 -13.13302503
##  [81] -13.37420317 -13.67834022 -14.02889961 -14.40414854 -14.77730940
##  [86] -15.11749541 -15.39208435 -15.57106927 -15.63311292 -15.57151749
##  [91] -15.39722851 -15.13692019 -14.82696395 -14.50622252 -14.21040074
##  [96] -13.96897449 -13.80426228 -13.73169224 -13.76044971 -13.89400346
## [101] -14.13027252 -14.46138142 -14.87311844 -15.34443090 -15.84758554
## [106] -16.34986662 -16.81750858 -17.22153106 -17.54346560 -17.77806885
## [111] -17.93148745 -18.01620729 -18.04583417 -18.03203751 -17.98407988
## [116] -17.90993918 -17.81767355 -17.71608913 -17.61445144 -17.52152841
## [121] -17.44446679 -17.38791989 -17.35363279 -17.34050359 -17.34503321
## [126] -17.36203822 -17.38549708 -17.40940880 -17.42856219 -17.43914307

The ACF plots shows a slowly dampening autocorrelation, along with the spectral density, there may be some frequency with the five peaks in the spectral density, however there is strong evidence of wandering behavior and stationary.

Now that we have a sense of the data lets see what a base time series model may yield

#First put the object into a ts object
ts_nly_open = ts(df.adj$Open, frequency = 1)
ts_nly_open.eco = ts(finaldata$Open, frequency = 1)

Fit at least one model from each of the following four categories (provide all plots and tables needed to ID these models: acfs, spectral density, factor tables, etc.):

a. ARMA / ARIMA / ARUMA / Signal Plus Noise (univariate analysis)

aic5.wge(ts_nly_open, p = 0:10, q = 0:10) #picks a 6:6 model, lets difference the data first
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Error in aic calculation at 7 7 
## Five Smallest Values of  aic 
##     p    q        aic
##     6    6  -3.078345
##     8    7  -3.050791
##     8    2  -3.048955
##     5    2  -3.045016
##     9    2  -3.041199
aic5.wge(ts_nly_open.eco, p = 0:10, q = 0:10) #picks a 6:5 model, lets difference the data first
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Error in aic calculation at 8 9 
## Five Smallest Values of  aic 
##     p    q        aic
##     6    5  -3.086153
##     6    6  -3.070210
##     8    2  -3.044905
##     6    4  -3.041284
##     5    2  -3.041058
#Original Dataset
diff_ts = artrans.wge(ts_nly_open, 1) # we get an acf plot at lag 1 as opposed to lag 0, lets difference the differences data

diff_two_ts = artrans.wge(diff_ts,1) # the acf lag has another pronounced at lag 2, however the first differences data may be better suited. We'll proceed with the first differenced data set.

#New Data Set
diff_ts.eco = artrans.wge(ts_nly_open.eco, 1) # we get an acf plot at lag 1 as opposed to lag 0, lets difference the differences data

diff_two_ts.eco = artrans.wge(diff_ts.eco,1) # the acf lag has another pronounced at lag 2, however the first differences data may be better suited. We'll proceed with the first differenced data set.

#Original Data Set
aic5.wge(diff_ts, p = 0:10, q = 0:10, type = "aic") # at iteration 80, AIC picks AR(7)MA(2) model
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  aic 
##     p    q        aic
##     7    2  -3.036156
##     4    2  -3.031027
##     7    3  -3.017738
##     2    9  -3.015115
##     3    0  -3.014866
aic5.wge(diff_ts, p= 0:10, q=0:10, type ="bic") # at iteration 75, BIC picks AR(0)MA(0) model
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Five Smallest Values of  bic 
##     p    q        bic
##     0    0  -2.996849
##     0    1  -2.976414
##     1    0  -2.976223
##     2    0  -2.967971
##     0    2  -2.967646
#New Data Set
aic5.wge(diff_ts.eco, p = 0:10, q = 0:10, type = "aic") # at iteration 80, AIC picks AR(7)MA(2) model
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Error in aic calculation at 6 6 
## Error in aic calculation at 6 10 
## Error in aic calculation at 7 8 
## Five Smallest Values of  aic 
##     p    q        aic
##     7    2  -3.032431
##     4    2  -3.027806
##     7    3  -3.013965
##     3    3  -3.011473
##     3    0  -3.010912
aic5.wge(diff_ts.eco, p= 0:10, q=0:10, type ="bic") # at iteration 75, BIC picks AR(0)MA(0) model
## ---------WORKING... PLEASE WAIT... 
## 
## 
## Error in aic calculation at 6 6 
## Error in aic calculation at 6 10 
## Error in aic calculation at 7 8 
## Five Smallest Values of  bic 
##     p    q        bic
##     0    0  -2.993063
##     0    1  -2.972567
##     1    0  -2.972376
##     2    0  -2.963938
##     0    2  -2.963613

Noting that the BIC choose a AR0MA0 model, however in the updated it suggests an MA(1) model for its second choice, this tells us that we have likely high degrees of wandering even after differences the data, we’ll model both, but give the BIC a straight seasonal component

#Original Data Set
#AIC Model AR(7)MA(2) model
aic_est = est.arma.wge(diff_ts, p = 7, q = 2)
##   
##   
## Coefficients of AR polynomial:  
## -1.4236 -1.0081 -0.0554 0.0271 0.0002 -0.1162 -0.1176 
## 
##                            AR Factor Table 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.4581B+0.9751B^2   -0.7476+-0.6830i      0.9875       0.3822
## 1+0.3322B+0.4935B^2   -0.3365+-1.3831i      0.7025       0.2880
## 1+0.6515B             -1.5349               0.6515       0.5000
## 1-1.0182B+0.3750B^2    1.3575+-0.9075i      0.6124       0.0938
##   
##   
##   
##   
## Coefficients of MA polynomial:  
## -1.4456 -0.9218 
## 
##                               MA FACTOR TABLE 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.4456B+0.9218B^2   -0.7841+-0.6856i      0.9601       0.3857
##   
## 
#BIC Model  AR(0)MA(0) model
bic_est = est.arma.wge(diff_ts, p = 0, q = 0)


#New Data Set
#AIC Model AR(7)MA(2) model
aic_est.eco = est.arma.wge(diff_ts.eco, p = 7, q = 2)
##   
##   
## Coefficients of AR polynomial:  
## -1.4233 -1.0093 -0.0568 0.0270 0.0011 -0.1166 -0.1186 
## 
##                            AR Factor Table 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.4584B+0.9756B^2   -0.7474+-0.6829i      0.9877       0.3822
## 1+0.3316B+0.4958B^2   -0.3344+-1.3802i      0.7042       0.2878
## 1+0.6524B             -1.5328               0.6524       0.5000
## 1-1.0192B+0.3757B^2    1.3566+-0.9065i      0.6129       0.0938
##   
##   
##   
##   
## Coefficients of MA polynomial:  
## -1.4460 -0.9222 
## 
##                               MA FACTOR TABLE 
## Factor                 Roots                Abs Recip    System Freq 
## 1+1.4460B+0.9222B^2   -0.7840+-0.6853i      0.9603       0.3857
##   
## 
#BIC Model  AR(0)MA(0) model
bic_est.eco = est.arma.wge(diff_ts.eco, p = 0, q = 0)

Comment here on the factor, the strong behavior is indicating that

# AIC Model Forecast
aic_fore.short = fore.arima.wge(ts_nly_open, phi = aic_est$phi, theta = aic_est$theta, d=1,n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

# BIC Model FOrecast
bic_fore.short = fore.arima.wge(ts_nly_open, phi = bic_est$phi, theta = bic_est$theta, d=1, n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

# Both are more or less the same model given the ARMA component cancel each other out 


# AIC Model Forecast
aic_fore.long = fore.arima.wge(ts_nly_open, phi = aic_est$phi, theta = aic_est$theta, d=1,n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

# BIC Model FOrecast
bic_fore.long = fore.arima.wge(ts_nly_open, phi = bic_est$phi, theta = bic_est$theta, d=1, n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

# AIC Model Forecast
aic_fore.short.eco = fore.arima.wge(ts_nly_open.eco, 
                                    phi = aic_est.eco$phi, 
                                    theta = aic_est.eco$theta, d=1,n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# BIC Model FOrecast
bic_fore.short.eco = fore.arima.wge(ts_nly_open.eco, 
                                    phi = bic_est.eco$phi, 
                                    theta = bic_est.eco$theta, d=1, n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# Both are more or less the same model given the ARMA component cancel each other out 


# AIC Model Forecast
aic_fore.long.eco = fore.arima.wge(ts_nly_open.eco, 
                                   phi = aic_est.eco$phi, 
                                   theta = aic_est.eco$theta, 
                                   d=1,n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# BIC Model FOrecast
bic_fore.long.eco = fore.arima.wge(ts_nly_open.eco, 
                                   phi = bic_est.eco$phi, 
                                   theta = bic_est.eco$theta, 
                                   d=1, n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

Both the long and short term horizon models appear to be hovering around the mean with significant upper and lower bounds to their forecasts predictions, however the new economic factors in the model seem to be catching closer to the forecasted projections.

min_aic_short = min(aic_fore.short$ll)
max_aic_long = max(aic_fore.short$ul)
aic_cl_range = c(min_aic_short, max_aic_long) 
print(aic_cl_range)
## [1]  9.283369 11.979865
min_aic_short = min(aic_fore.long$ll)
max_aic_long = max(aic_fore.long$ul)
aic_cl_range = c(min_aic_short, max_aic_long) 
print(aic_cl_range)
## [1]  8.810912 12.252245
min_aic_short.eco = min(aic_fore.short.eco$ll)
max_aic_long.eco = max(aic_fore.short.eco$ul)
aic_cl_range.eco = c(min_aic_short.eco, max_aic_long.eco) 
print(aic_cl_range.eco)
## [1]  9.307398 12.007531
min_aic_short.eco = min(aic_fore.long.eco$ll)
max_aic_long.eco = max(aic_fore.long.eco$ul)
aic_cl_range.eco = c(min_aic_short.eco, max_aic_long.eco) 
print(aic_cl_range.eco)
## [1]  8.624272 12.063953
ase_aic_univariate.short = mean((ts_nly_open[251:262] - aic_fore.short$f)^2)
ase_aic_univariate.long = mean((ts_nly_open[243:262] - aic_fore.long$f)^2)

ase_aic_univariate.short #Original = 0.3818423
## [1] 0.3818423
ase_aic_univariate.long #Original =  0.1671257
## [1] 0.1671257
ase_aic_univariate.short.eco = mean((ts_nly_open.eco[250:261] - aic_fore.short.eco$f)^2)
ase_aic_univariate.long.eco = mean((ts_nly_open.eco[242:261] - aic_fore.long.eco$f)^2)

ase_aic_univariate.short.eco #New = 0.3179122
## [1] 0.3179122
ase_aic_univariate.long.eco #New =  0.08804297
## [1] 0.08804297
min_bic_short = min(bic_fore.short$ll)
max_bic_long = max(bic_fore.short$ul)
bic_cl_range = c(min_bic_short, max_bic_long) 
print(bic_cl_range)
## [1]  9.158755 12.161245
min_bic_short = min(bic_fore.long$ll)
max_bic_long = max(bic_fore.long$ul)
bic_cl_range = c(min_bic_short, max_bic_long) 
print(bic_cl_range)
## [1]  8.601901 12.478099
min_bic_short.eco = min(bic_fore.short.eco$ll)
max_bic_long.eco = max(bic_fore.short.eco$ul)
bic_cl_range.eco = c(min_bic_short.eco, max_bic_long.eco) 
print(bic_cl_range.eco)
## [1]  9.115961 12.124039
min_bic_short.eco = min(bic_fore.long.eco$ll)
max_bic_long.eco = max(bic_fore.long.eco$ul)
bic_cl_range.eco = c(min_bic_short.eco, max_bic_long.eco) 
print(bic_cl_range.eco)
## [1]  8.358294 12.241706
ase_bic_univariate.short = mean((ts_nly_open[251:262] - bic_fore.short$f)^2)
ase_bic_univariate.long = mean((ts_nly_open[243:262] - bic_fore.long$f)^2)

ase_bic_univariate.short # Original ASE [1] 0.3891917
## [1] 0.3891917
ase_bic_univariate.long # Original ASE [1] 0.16209
## [1] 0.16209
ase_bic_univariate.short.eco = mean((ts_nly_open.eco[250:261] - bic_fore.short.eco$f)^2)
ase_bic_univariate.long.eco = mean((ts_nly_open.eco[242:261] - bic_fore.long.eco$f)^2)

ase_bic_univariate.short.eco # New ASE [1] 0.3069167
## [1] 0.3069167
ase_bic_univariate.long.eco # New ASE [1] 0.085885
## [1] 0.085885
roll.win.rmse.wge(ts_nly_open, horizon = 12, d = 1 )
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 247 windows."
## y.arma -0.02 -0.48 0.24

## y.arma -0.48 0.24 0.17

## y.arma 0.24 0.17 -0.29

## y.arma 0.17 -0.29 0.21

## y.arma -0.29 0.21 0.22

## y.arma 0.21 0.22 -0.04

## y.arma 0.22 -0.04 0.32

## y.arma -0.04 0.32 0.26

## y.arma 0.32 0.26 0.14

## y.arma 0.26 0.14 -0.14

## y.arma 0.14 -0.14 -0.02

## y.arma -0.14 -0.02 0.42

## y.arma -0.02 0.42 -0.2

## y.arma 0.42 -0.2 0.36

## y.arma -0.2 0.36 0.09

## y.arma 0.36 0.09 -0.52

## y.arma 0.09 -0.52 0.09

## y.arma -0.52 0.09 0.43

## y.arma 0.09 0.43 -0.19

## y.arma 0.43 -0.19 0.28

## y.arma -0.19 0.28 0.03

## y.arma 0.28 0.03 0.05

## y.arma 0.03 0.05 0.08

## y.arma 0.05 0.08 0.09

## y.arma 0.08 0.09 0.02

## y.arma 0.09 0.02 -0.17

## y.arma 0.02 -0.17 0

## y.arma -0.17 0 0.03

## y.arma 0 0.03 -0.22

## y.arma 0.03 -0.22 -0.37

## y.arma -0.22 -0.37 0.08

## y.arma -0.37 0.08 0.1

## y.arma 0.08 0.1 0.08

## y.arma 0.1 0.08 -0.08

## y.arma 0.08 -0.08 0.19

## y.arma -0.08 0.19 0.33

## y.arma 0.19 0.33 0.02

## y.arma 0.33 0.02 0.12

## y.arma 0.02 0.12 -0.1

## y.arma 0.12 -0.1 -0.43

## y.arma -0.1 -0.43 -0.04

## y.arma -0.43 -0.04 -0.44

## y.arma -0.04 -0.44 -0.11

## y.arma -0.44 -0.11 0.41

## y.arma -0.11 0.41 -0.01

## y.arma 0.41 -0.01 0.16

## y.arma -0.01 0.16 0.04

## y.arma 0.16 0.04 -0.15

## y.arma 0.04 -0.15 0.16

## y.arma -0.15 0.16 0.11

## y.arma 0.16 0.11 0.01

## y.arma 0.11 0.01 -0.07

## y.arma 0.01 -0.07 -0.03

## y.arma -0.07 -0.03 -0.08

## y.arma -0.03 -0.08 -0.3

## y.arma -0.08 -0.3 -0.06

## y.arma -0.3 -0.06 -0.18

## y.arma -0.06 -0.18 -0.18

## y.arma -0.18 -0.18 -0.07

## y.arma -0.18 -0.07 -0.01

## y.arma -0.07 -0.01 -0.04

## y.arma -0.01 -0.04 0.14

## y.arma -0.04 0.14 0.08

## y.arma 0.14 0.08 -0.1

## y.arma 0.08 -0.1 -0.19

## y.arma -0.1 -0.19 0.04

## y.arma -0.19 0.04 0.27

## y.arma 0.04 0.27 -0.21

## y.arma 0.27 -0.21 -0.08

## y.arma -0.21 -0.08 -0.06

## y.arma -0.08 -0.06 -0.09

## y.arma -0.06 -0.09 -0.07

## y.arma -0.09 -0.07 -0.13

## y.arma -0.07 -0.13 -0.03

## y.arma -0.13 -0.03 0.08

## y.arma -0.03 0.08 0.1

## y.arma 0.08 0.1 0.2

## y.arma 0.1 0.2 -0.52

## y.arma 0.2 -0.52 -0.01

## y.arma -0.52 -0.01 0.01

## y.arma -0.01 0.01 -0.67

## y.arma 0.01 -0.67 0.06

## y.arma -0.67 0.06 0.18

## y.arma 0.06 0.18 0.28

## y.arma 0.18 0.28 -0.22

## y.arma 0.28 -0.22 0.4

## y.arma -0.22 0.4 0.13

## y.arma 0.4 0.13 0.29

## y.arma 0.13 0.29 -0.51

## y.arma 0.29 -0.51 0.3

## y.arma -0.51 0.3 0.03

## y.arma 0.3 0.03 -0.09

## y.arma 0.03 -0.09 0.27

## y.arma -0.09 0.27 -0.29

## y.arma 0.27 -0.29 -0.09

## y.arma -0.29 -0.09 0.24

## y.arma -0.09 0.24 -0.1

## y.arma 0.24 -0.1 0.07

## y.arma -0.1 0.07 -0.26

## y.arma 0.07 -0.26 -0.48

## y.arma -0.26 -0.48 0.1

## y.arma -0.48 0.1 -0.02

## y.arma 0.1 -0.02 0.12

## y.arma -0.02 0.12 -0.19

## y.arma 0.12 -0.19 -0.27

## y.arma -0.19 -0.27 0.31

## y.arma -0.27 0.31 0.24

## y.arma 0.31 0.24 -0.44

## y.arma 0.24 -0.44 0.06

## y.arma -0.44 0.06 -0.41

## y.arma 0.06 -0.41 0.06

## y.arma -0.41 0.06 0.46

## y.arma 0.06 0.46 0.22

## y.arma 0.46 0.22 0.06

## y.arma 0.22 0.06 0.2

## y.arma 0.06 0.2 0.23

## y.arma 0.2 0.23 0.1

## y.arma 0.23 0.1 -0.01

## y.arma 0.1 -0.01 0.12

## y.arma -0.01 0.12 0.04

## y.arma 0.12 0.04 -0.12

## y.arma 0.04 -0.12 -0.17

## y.arma -0.12 -0.17 0.24

## y.arma -0.17 0.24 -0.17

## y.arma 0.24 -0.17 0.2

## y.arma -0.17 0.2 0.45

## y.arma 0.2 0.45 0.15

## y.arma 0.45 0.15 -0.07

## y.arma 0.15 -0.07 -0.34

## y.arma -0.07 -0.34 0.21

## y.arma -0.34 0.21 -0.03

## y.arma 0.21 -0.03 -0.2

## y.arma -0.03 -0.2 0.31

## y.arma -0.2 0.31 0.05

## y.arma 0.31 0.05 -0.17

## y.arma 0.05 -0.17 -0.14

## y.arma -0.17 -0.14 0.25

## y.arma -0.14 0.25 0.08

## y.arma 0.25 0.08 0.11

## y.arma 0.08 0.11 -0.03

## y.arma 0.11 -0.03 -0.13

## y.arma -0.03 -0.13 -0.13

## y.arma -0.13 -0.13 0.1

## y.arma -0.13 0.1 -0.49

## y.arma 0.1 -0.49 0.06

## y.arma -0.49 0.06 0.32

## y.arma 0.06 0.32 -0.32

## y.arma 0.32 -0.32 -0.42

## y.arma -0.32 -0.42 0.1

## y.arma -0.42 0.1 -0.04

## y.arma 0.1 -0.04 0.17

## y.arma -0.04 0.17 0.07

## y.arma 0.17 0.07 -0.25

## y.arma 0.07 -0.25 -0.07

## y.arma -0.25 -0.07 0.08

## y.arma -0.07 0.08 -0.13

## y.arma 0.08 -0.13 0.49

## y.arma -0.13 0.49 -0.25

## y.arma 0.49 -0.25 0.11

## y.arma -0.25 0.11 -0.31

## y.arma 0.11 -0.31 0.24

## y.arma -0.31 0.24 -0.11

## y.arma 0.24 -0.11 0.01

## y.arma -0.11 0.01 0.09

## y.arma 0.01 0.09 0.06

## y.arma 0.09 0.06 0.24

## y.arma 0.06 0.24 0.3

## y.arma 0.24 0.3 0.23

## y.arma 0.3 0.23 -0.12

## y.arma 0.23 -0.12 0

## y.arma -0.12 0 0.06

## y.arma 0 0.06 0.12

## y.arma 0.06 0.12 -0.03

## y.arma 0.12 -0.03 0.19

## y.arma -0.03 0.19 0.33

## y.arma 0.19 0.33 0.15

## y.arma 0.33 0.15 0.06

## y.arma 0.15 0.06 -0.26

## y.arma 0.06 -0.26 -0.28

## y.arma -0.26 -0.28 0.23

## y.arma -0.28 0.23 0.28

## y.arma 0.23 0.28 0.21

## y.arma 0.28 0.21 0.11

## y.arma 0.21 0.11 0.26

## y.arma 0.11 0.26 0.22

## y.arma 0.26 0.22 -0.56

## y.arma 0.22 -0.56 0.02

## y.arma -0.56 0.02 0.26

## y.arma 0.02 0.26 -0.42

## y.arma 0.26 -0.42 0.06

## y.arma -0.42 0.06 0.04

## y.arma 0.06 0.04 0.3

## y.arma 0.04 0.3 0.06

## y.arma 0.3 0.06 0.01

## y.arma 0.06 0.01 0.09

## y.arma 0.01 0.09 -0.07

## y.arma 0.09 -0.07 -0.05

## y.arma -0.07 -0.05 0.12

## y.arma -0.05 0.12 -0.26

## y.arma 0.12 -0.26 -0.06

## y.arma -0.26 -0.06 0.09

## y.arma -0.06 0.09 0.02

## y.arma 0.09 0.02 -0.67

## y.arma 0.02 -0.67 -0.39

## y.arma -0.67 -0.39 0.01

## y.arma -0.39 0.01 0.29

## y.arma 0.01 0.29 0.29

## y.arma 0.29 0.29 0.06

## y.arma 0.29 0.06 0.12

## y.arma 0.06 0.12 0.29

## y.arma 0.12 0.29 -0.2

## y.arma 0.29 -0.2 -0.17

## y.arma -0.2 -0.17 -0.32

## y.arma -0.17 -0.32 -0.26

## y.arma -0.32 -0.26 -0.08

## y.arma -0.26 -0.08 -0.35

## y.arma -0.08 -0.35 -0.56

## y.arma -0.35 -0.56 -0.09

## y.arma -0.56 -0.09 0.38

## y.arma -0.09 0.38 -0.18

## y.arma 0.38 -0.18 -0.33

## y.arma -0.18 -0.33 0.25

## y.arma -0.33 0.25 0.27

## y.arma 0.25 0.27 -0.06

## y.arma 0.27 -0.06 -0.16

## y.arma -0.06 -0.16 0.1

## y.arma -0.16 0.1 -0.19

## y.arma 0.1 -0.19 -0.03

## y.arma -0.19 -0.03 0.21

## y.arma -0.03 0.21 -0.13

## y.arma 0.21 -0.13 0.06

## y.arma -0.13 0.06 0.01

## y.arma 0.06 0.01 0

## y.arma 0.01 0 0.07

## y.arma 0 0.07 0.05

## y.arma 0.07 0.05 -0.08

## y.arma 0.05 -0.08 0.16

## y.arma -0.08 0.16 -0.33

## y.arma 0.16 -0.33 0.24

## y.arma -0.33 0.24 -0.12

## y.arma 0.24 -0.12 0.07

## y.arma -0.12 0.07 0.09

## y.arma 0.07 0.09 -0.03

## y.arma 0.09 -0.03 -0.13

## y.arma -0.03 -0.13 0.27

## y.arma -0.13 0.27 -0.07

## y.arma 0.27 -0.07 0.04

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.08954 0.27891 0.40805 0.45852 0.60149 1.49417 
## [1] "The Rolling Window RMSE is:  0.459"
roll.win.rmse.wge(ts_nly_open.eco, horizon = 12, d = 1 )
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 246 windows."
## y.arma -0.02 -0.48 0.24

## y.arma -0.48 0.24 0.17

## y.arma 0.24 0.17 -0.29

## y.arma 0.17 -0.29 0.21

## y.arma -0.29 0.21 0.22

## y.arma 0.21 0.22 -0.04

## y.arma 0.22 -0.04 0.32

## y.arma -0.04 0.32 0.26

## y.arma 0.32 0.26 0.14

## y.arma 0.26 0.14 -0.14

## y.arma 0.14 -0.14 -0.02

## y.arma -0.14 -0.02 0.42

## y.arma -0.02 0.42 -0.2

## y.arma 0.42 -0.2 0.36

## y.arma -0.2 0.36 0.09

## y.arma 0.36 0.09 -0.52

## y.arma 0.09 -0.52 0.09

## y.arma -0.52 0.09 0.43

## y.arma 0.09 0.43 -0.19

## y.arma 0.43 -0.19 0.28

## y.arma -0.19 0.28 0.03

## y.arma 0.28 0.03 0.05

## y.arma 0.03 0.05 0.08

## y.arma 0.05 0.08 0.09

## y.arma 0.08 0.09 0.02

## y.arma 0.09 0.02 -0.17

## y.arma 0.02 -0.17 0

## y.arma -0.17 0 0.03

## y.arma 0 0.03 -0.22

## y.arma 0.03 -0.22 -0.37

## y.arma -0.22 -0.37 0.08

## y.arma -0.37 0.08 0.1

## y.arma 0.08 0.1 0.08

## y.arma 0.1 0.08 -0.08

## y.arma 0.08 -0.08 0.19

## y.arma -0.08 0.19 0.33

## y.arma 0.19 0.33 0.02

## y.arma 0.33 0.02 0.12

## y.arma 0.02 0.12 -0.1

## y.arma 0.12 -0.1 -0.43

## y.arma -0.1 -0.43 -0.04

## y.arma -0.43 -0.04 -0.44

## y.arma -0.04 -0.44 -0.11

## y.arma -0.44 -0.11 0.41

## y.arma -0.11 0.41 -0.01

## y.arma 0.41 -0.01 0.16

## y.arma -0.01 0.16 0.04

## y.arma 0.16 0.04 -0.15

## y.arma 0.04 -0.15 0.16

## y.arma -0.15 0.16 0.11

## y.arma 0.16 0.11 0.01

## y.arma 0.11 0.01 -0.07

## y.arma 0.01 -0.07 -0.03

## y.arma -0.07 -0.03 -0.08

## y.arma -0.03 -0.08 -0.3

## y.arma -0.08 -0.3 -0.06

## y.arma -0.3 -0.06 -0.18

## y.arma -0.06 -0.18 -0.18

## y.arma -0.18 -0.18 -0.07

## y.arma -0.18 -0.07 -0.01

## y.arma -0.07 -0.01 -0.04

## y.arma -0.01 -0.04 0.14

## y.arma -0.04 0.14 0.08

## y.arma 0.14 0.08 -0.1

## y.arma 0.08 -0.1 -0.19

## y.arma -0.1 -0.19 0.04

## y.arma -0.19 0.04 0.27

## y.arma 0.04 0.27 -0.21

## y.arma 0.27 -0.21 -0.08

## y.arma -0.21 -0.08 -0.06

## y.arma -0.08 -0.06 -0.09

## y.arma -0.06 -0.09 -0.07

## y.arma -0.09 -0.07 -0.13

## y.arma -0.07 -0.13 -0.03

## y.arma -0.13 -0.03 0.08

## y.arma -0.03 0.08 0.1

## y.arma 0.08 0.1 0.2

## y.arma 0.1 0.2 -0.52

## y.arma 0.2 -0.52 -0.01

## y.arma -0.52 -0.01 0.01

## y.arma -0.01 0.01 -0.67

## y.arma 0.01 -0.67 0.06

## y.arma -0.67 0.06 0.18

## y.arma 0.06 0.18 0.28

## y.arma 0.18 0.28 -0.22

## y.arma 0.28 -0.22 0.4

## y.arma -0.22 0.4 0.13

## y.arma 0.4 0.13 0.29

## y.arma 0.13 0.29 -0.51

## y.arma 0.29 -0.51 0.3

## y.arma -0.51 0.3 0.03

## y.arma 0.3 0.03 -0.09

## y.arma 0.03 -0.09 0.27

## y.arma -0.09 0.27 -0.29

## y.arma 0.27 -0.29 -0.09

## y.arma -0.29 -0.09 0.24

## y.arma -0.09 0.24 -0.1

## y.arma 0.24 -0.1 0.07

## y.arma -0.1 0.07 -0.26

## y.arma 0.07 -0.26 -0.48

## y.arma -0.26 -0.48 0.1

## y.arma -0.48 0.1 -0.02

## y.arma 0.1 -0.02 0.12

## y.arma -0.02 0.12 -0.19

## y.arma 0.12 -0.19 -0.27

## y.arma -0.19 -0.27 0.31

## y.arma -0.27 0.31 0.24

## y.arma 0.31 0.24 -0.44

## y.arma 0.24 -0.44 0.06

## y.arma -0.44 0.06 -0.41

## y.arma 0.06 -0.41 0.06

## y.arma -0.41 0.06 0.46

## y.arma 0.06 0.46 0.22

## y.arma 0.46 0.22 0.06

## y.arma 0.22 0.06 0.2

## y.arma 0.06 0.2 0.23

## y.arma 0.2 0.23 0.1

## y.arma 0.23 0.1 -0.01

## y.arma 0.1 -0.01 0.12

## y.arma -0.01 0.12 0.04

## y.arma 0.12 0.04 -0.12

## y.arma 0.04 -0.12 -0.17

## y.arma -0.12 -0.17 0.24

## y.arma -0.17 0.24 -0.17

## y.arma 0.24 -0.17 0.2

## y.arma -0.17 0.2 0.45

## y.arma 0.2 0.45 0.15

## y.arma 0.45 0.15 -0.07

## y.arma 0.15 -0.07 -0.34

## y.arma -0.07 -0.34 0.21

## y.arma -0.34 0.21 -0.03

## y.arma 0.21 -0.03 -0.2

## y.arma -0.03 -0.2 0.31

## y.arma -0.2 0.31 0.05

## y.arma 0.31 0.05 -0.17

## y.arma 0.05 -0.17 -0.14

## y.arma -0.17 -0.14 0.25

## y.arma -0.14 0.25 0.08

## y.arma 0.25 0.08 0.11

## y.arma 0.08 0.11 -0.03

## y.arma 0.11 -0.03 -0.13

## y.arma -0.03 -0.13 -0.13

## y.arma -0.13 -0.13 0.1

## y.arma -0.13 0.1 -0.49

## y.arma 0.1 -0.49 0.06

## y.arma -0.49 0.06 0.32

## y.arma 0.06 0.32 -0.32

## y.arma 0.32 -0.32 -0.42

## y.arma -0.32 -0.42 0.1

## y.arma -0.42 0.1 -0.04

## y.arma 0.1 -0.04 0.17

## y.arma -0.04 0.17 0.07

## y.arma 0.17 0.07 -0.25

## y.arma 0.07 -0.25 -0.07

## y.arma -0.25 -0.07 0.08

## y.arma -0.07 0.08 -0.13

## y.arma 0.08 -0.13 0.49

## y.arma -0.13 0.49 -0.25

## y.arma 0.49 -0.25 0.11

## y.arma -0.25 0.11 -0.31

## y.arma 0.11 -0.31 0.24

## y.arma -0.31 0.24 -0.11

## y.arma 0.24 -0.11 0.01

## y.arma -0.11 0.01 0.09

## y.arma 0.01 0.09 0.06

## y.arma 0.09 0.06 0.24

## y.arma 0.06 0.24 0.3

## y.arma 0.24 0.3 0.23

## y.arma 0.3 0.23 -0.12

## y.arma 0.23 -0.12 0

## y.arma -0.12 0 0.06

## y.arma 0 0.06 0.12

## y.arma 0.06 0.12 -0.03

## y.arma 0.12 -0.03 0.19

## y.arma -0.03 0.19 0.33

## y.arma 0.19 0.33 0.15

## y.arma 0.33 0.15 0.06

## y.arma 0.15 0.06 -0.26

## y.arma 0.06 -0.26 -0.28

## y.arma -0.26 -0.28 0.23

## y.arma -0.28 0.23 0.28

## y.arma 0.23 0.28 0.21

## y.arma 0.28 0.21 0.11

## y.arma 0.21 0.11 0.26

## y.arma 0.11 0.26 0.22

## y.arma 0.26 0.22 -0.56

## y.arma 0.22 -0.56 0.02

## y.arma -0.56 0.02 0.26

## y.arma 0.02 0.26 -0.42

## y.arma 0.26 -0.42 0.06

## y.arma -0.42 0.06 0.04

## y.arma 0.06 0.04 0.3

## y.arma 0.04 0.3 0.06

## y.arma 0.3 0.06 0.01

## y.arma 0.06 0.01 0.09

## y.arma 0.01 0.09 -0.07

## y.arma 0.09 -0.07 -0.05

## y.arma -0.07 -0.05 0.12

## y.arma -0.05 0.12 -0.26

## y.arma 0.12 -0.26 -0.06

## y.arma -0.26 -0.06 0.09

## y.arma -0.06 0.09 0.02

## y.arma 0.09 0.02 -0.67

## y.arma 0.02 -0.67 -0.39

## y.arma -0.67 -0.39 0.01

## y.arma -0.39 0.01 0.29

## y.arma 0.01 0.29 0.29

## y.arma 0.29 0.29 0.06

## y.arma 0.29 0.06 0.12

## y.arma 0.06 0.12 0.29

## y.arma 0.12 0.29 -0.2

## y.arma 0.29 -0.2 -0.17

## y.arma -0.2 -0.17 -0.32

## y.arma -0.17 -0.32 -0.26

## y.arma -0.32 -0.26 -0.08

## y.arma -0.26 -0.08 -0.35

## y.arma -0.08 -0.35 -0.56

## y.arma -0.35 -0.56 -0.09

## y.arma -0.56 -0.09 0.38

## y.arma -0.09 0.38 -0.18

## y.arma 0.38 -0.18 -0.33

## y.arma -0.18 -0.33 0.25

## y.arma -0.33 0.25 0.27

## y.arma 0.25 0.27 -0.06

## y.arma 0.27 -0.06 -0.16

## y.arma -0.06 -0.16 0.1

## y.arma -0.16 0.1 -0.19

## y.arma 0.1 -0.19 -0.03

## y.arma -0.19 -0.03 0.21

## y.arma -0.03 0.21 -0.13

## y.arma 0.21 -0.13 0.06

## y.arma -0.13 0.06 0.01

## y.arma 0.06 0.01 0

## y.arma 0.01 0 0.07

## y.arma 0 0.07 0.05

## y.arma 0.07 0.05 -0.08

## y.arma 0.05 -0.08 0.16

## y.arma -0.08 0.16 -0.33

## y.arma 0.16 -0.33 0.24

## y.arma -0.33 0.24 -0.12

## y.arma 0.24 -0.12 0.07

## y.arma -0.12 0.07 0.09

## y.arma 0.07 0.09 -0.03

## y.arma 0.09 -0.03 -0.13

## y.arma -0.03 -0.13 0.27

## y.arma -0.13 0.27 -0.07

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
## 0.08954 0.27810 0.40744 0.45784 0.59719 1.49417 
## [1] "The Rolling Window RMSE is:  0.458"
# Original Score:
# [1] "The Summary Statistics for the Rolling Window RMSE Are:"
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
# 0.08954 0.27891 0.40805 0.45852 0.60149 1.49417 
# [1] "The Rolling Window RMSE is:  0.459"

# New Score:
# [1] "The Summary Statistics for the Rolling Window RMSE Are:"
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
# 0.08954 0.27891 0.40805 0.45852 0.60149 1.49417 
# [1] "The Rolling Window RMSE is:  0.459"

We can note that there was no difference at all in the RSME from the Rolling window short horizon model with or without the additional economic factors.

roll.win.rmse.wge(ts_nly_open, horizon = 20, d = 1 )
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 239 windows."
## y.arma -0.02 -0.48 0.24

## y.arma -0.48 0.24 0.17

## y.arma 0.24 0.17 -0.29

## y.arma 0.17 -0.29 0.21

## y.arma -0.29 0.21 0.22

## y.arma 0.21 0.22 -0.04

## y.arma 0.22 -0.04 0.32

## y.arma -0.04 0.32 0.26

## y.arma 0.32 0.26 0.14

## y.arma 0.26 0.14 -0.14

## y.arma 0.14 -0.14 -0.02

## y.arma -0.14 -0.02 0.42

## y.arma -0.02 0.42 -0.2

## y.arma 0.42 -0.2 0.36

## y.arma -0.2 0.36 0.09

## y.arma 0.36 0.09 -0.52

## y.arma 0.09 -0.52 0.09

## y.arma -0.52 0.09 0.43

## y.arma 0.09 0.43 -0.19

## y.arma 0.43 -0.19 0.28

## y.arma -0.19 0.28 0.03

## y.arma 0.28 0.03 0.05

## y.arma 0.03 0.05 0.08

## y.arma 0.05 0.08 0.09

## y.arma 0.08 0.09 0.02

## y.arma 0.09 0.02 -0.17

## y.arma 0.02 -0.17 0

## y.arma -0.17 0 0.03

## y.arma 0 0.03 -0.22

## y.arma 0.03 -0.22 -0.37

## y.arma -0.22 -0.37 0.08

## y.arma -0.37 0.08 0.1

## y.arma 0.08 0.1 0.08

## y.arma 0.1 0.08 -0.08

## y.arma 0.08 -0.08 0.19

## y.arma -0.08 0.19 0.33

## y.arma 0.19 0.33 0.02

## y.arma 0.33 0.02 0.12

## y.arma 0.02 0.12 -0.1

## y.arma 0.12 -0.1 -0.43

## y.arma -0.1 -0.43 -0.04

## y.arma -0.43 -0.04 -0.44

## y.arma -0.04 -0.44 -0.11

## y.arma -0.44 -0.11 0.41

## y.arma -0.11 0.41 -0.01

## y.arma 0.41 -0.01 0.16

## y.arma -0.01 0.16 0.04

## y.arma 0.16 0.04 -0.15

## y.arma 0.04 -0.15 0.16

## y.arma -0.15 0.16 0.11

## y.arma 0.16 0.11 0.01

## y.arma 0.11 0.01 -0.07

## y.arma 0.01 -0.07 -0.03

## y.arma -0.07 -0.03 -0.08

## y.arma -0.03 -0.08 -0.3

## y.arma -0.08 -0.3 -0.06

## y.arma -0.3 -0.06 -0.18

## y.arma -0.06 -0.18 -0.18

## y.arma -0.18 -0.18 -0.07

## y.arma -0.18 -0.07 -0.01

## y.arma -0.07 -0.01 -0.04

## y.arma -0.01 -0.04 0.14

## y.arma -0.04 0.14 0.08

## y.arma 0.14 0.08 -0.1

## y.arma 0.08 -0.1 -0.19

## y.arma -0.1 -0.19 0.04

## y.arma -0.19 0.04 0.27

## y.arma 0.04 0.27 -0.21

## y.arma 0.27 -0.21 -0.08

## y.arma -0.21 -0.08 -0.06

## y.arma -0.08 -0.06 -0.09

## y.arma -0.06 -0.09 -0.07

## y.arma -0.09 -0.07 -0.13

## y.arma -0.07 -0.13 -0.03

## y.arma -0.13 -0.03 0.08

## y.arma -0.03 0.08 0.1

## y.arma 0.08 0.1 0.2

## y.arma 0.1 0.2 -0.52

## y.arma 0.2 -0.52 -0.01

## y.arma -0.52 -0.01 0.01

## y.arma -0.01 0.01 -0.67

## y.arma 0.01 -0.67 0.06

## y.arma -0.67 0.06 0.18

## y.arma 0.06 0.18 0.28

## y.arma 0.18 0.28 -0.22

## y.arma 0.28 -0.22 0.4

## y.arma -0.22 0.4 0.13

## y.arma 0.4 0.13 0.29

## y.arma 0.13 0.29 -0.51

## y.arma 0.29 -0.51 0.3

## y.arma -0.51 0.3 0.03

## y.arma 0.3 0.03 -0.09

## y.arma 0.03 -0.09 0.27

## y.arma -0.09 0.27 -0.29

## y.arma 0.27 -0.29 -0.09

## y.arma -0.29 -0.09 0.24

## y.arma -0.09 0.24 -0.1

## y.arma 0.24 -0.1 0.07

## y.arma -0.1 0.07 -0.26

## y.arma 0.07 -0.26 -0.48

## y.arma -0.26 -0.48 0.1

## y.arma -0.48 0.1 -0.02

## y.arma 0.1 -0.02 0.12

## y.arma -0.02 0.12 -0.19

## y.arma 0.12 -0.19 -0.27

## y.arma -0.19 -0.27 0.31

## y.arma -0.27 0.31 0.24

## y.arma 0.31 0.24 -0.44

## y.arma 0.24 -0.44 0.06

## y.arma -0.44 0.06 -0.41

## y.arma 0.06 -0.41 0.06

## y.arma -0.41 0.06 0.46

## y.arma 0.06 0.46 0.22

## y.arma 0.46 0.22 0.06

## y.arma 0.22 0.06 0.2

## y.arma 0.06 0.2 0.23

## y.arma 0.2 0.23 0.1

## y.arma 0.23 0.1 -0.01

## y.arma 0.1 -0.01 0.12

## y.arma -0.01 0.12 0.04

## y.arma 0.12 0.04 -0.12

## y.arma 0.04 -0.12 -0.17

## y.arma -0.12 -0.17 0.24

## y.arma -0.17 0.24 -0.17

## y.arma 0.24 -0.17 0.2

## y.arma -0.17 0.2 0.45

## y.arma 0.2 0.45 0.15

## y.arma 0.45 0.15 -0.07

## y.arma 0.15 -0.07 -0.34

## y.arma -0.07 -0.34 0.21

## y.arma -0.34 0.21 -0.03

## y.arma 0.21 -0.03 -0.2

## y.arma -0.03 -0.2 0.31

## y.arma -0.2 0.31 0.05

## y.arma 0.31 0.05 -0.17

## y.arma 0.05 -0.17 -0.14

## y.arma -0.17 -0.14 0.25

## y.arma -0.14 0.25 0.08

## y.arma 0.25 0.08 0.11

## y.arma 0.08 0.11 -0.03

## y.arma 0.11 -0.03 -0.13

## y.arma -0.03 -0.13 -0.13

## y.arma -0.13 -0.13 0.1

## y.arma -0.13 0.1 -0.49

## y.arma 0.1 -0.49 0.06

## y.arma -0.49 0.06 0.32

## y.arma 0.06 0.32 -0.32

## y.arma 0.32 -0.32 -0.42

## y.arma -0.32 -0.42 0.1

## y.arma -0.42 0.1 -0.04

## y.arma 0.1 -0.04 0.17

## y.arma -0.04 0.17 0.07

## y.arma 0.17 0.07 -0.25

## y.arma 0.07 -0.25 -0.07

## y.arma -0.25 -0.07 0.08

## y.arma -0.07 0.08 -0.13

## y.arma 0.08 -0.13 0.49

## y.arma -0.13 0.49 -0.25

## y.arma 0.49 -0.25 0.11

## y.arma -0.25 0.11 -0.31

## y.arma 0.11 -0.31 0.24

## y.arma -0.31 0.24 -0.11

## y.arma 0.24 -0.11 0.01

## y.arma -0.11 0.01 0.09

## y.arma 0.01 0.09 0.06

## y.arma 0.09 0.06 0.24

## y.arma 0.06 0.24 0.3

## y.arma 0.24 0.3 0.23

## y.arma 0.3 0.23 -0.12

## y.arma 0.23 -0.12 0

## y.arma -0.12 0 0.06

## y.arma 0 0.06 0.12

## y.arma 0.06 0.12 -0.03

## y.arma 0.12 -0.03 0.19

## y.arma -0.03 0.19 0.33

## y.arma 0.19 0.33 0.15

## y.arma 0.33 0.15 0.06

## y.arma 0.15 0.06 -0.26

## y.arma 0.06 -0.26 -0.28

## y.arma -0.26 -0.28 0.23

## y.arma -0.28 0.23 0.28

## y.arma 0.23 0.28 0.21

## y.arma 0.28 0.21 0.11

## y.arma 0.21 0.11 0.26

## y.arma 0.11 0.26 0.22

## y.arma 0.26 0.22 -0.56

## y.arma 0.22 -0.56 0.02

## y.arma -0.56 0.02 0.26

## y.arma 0.02 0.26 -0.42

## y.arma 0.26 -0.42 0.06

## y.arma -0.42 0.06 0.04

## y.arma 0.06 0.04 0.3

## y.arma 0.04 0.3 0.06

## y.arma 0.3 0.06 0.01

## y.arma 0.06 0.01 0.09

## y.arma 0.01 0.09 -0.07

## y.arma 0.09 -0.07 -0.05

## y.arma -0.07 -0.05 0.12

## y.arma -0.05 0.12 -0.26

## y.arma 0.12 -0.26 -0.06

## y.arma -0.26 -0.06 0.09

## y.arma -0.06 0.09 0.02

## y.arma 0.09 0.02 -0.67

## y.arma 0.02 -0.67 -0.39

## y.arma -0.67 -0.39 0.01

## y.arma -0.39 0.01 0.29

## y.arma 0.01 0.29 0.29

## y.arma 0.29 0.29 0.06

## y.arma 0.29 0.06 0.12

## y.arma 0.06 0.12 0.29

## y.arma 0.12 0.29 -0.2

## y.arma 0.29 -0.2 -0.17

## y.arma -0.2 -0.17 -0.32

## y.arma -0.17 -0.32 -0.26

## y.arma -0.32 -0.26 -0.08

## y.arma -0.26 -0.08 -0.35

## y.arma -0.08 -0.35 -0.56

## y.arma -0.35 -0.56 -0.09

## y.arma -0.56 -0.09 0.38

## y.arma -0.09 0.38 -0.18

## y.arma 0.38 -0.18 -0.33

## y.arma -0.18 -0.33 0.25

## y.arma -0.33 0.25 0.27

## y.arma 0.25 0.27 -0.06

## y.arma 0.27 -0.06 -0.16

## y.arma -0.06 -0.16 0.1

## y.arma -0.16 0.1 -0.19

## y.arma 0.1 -0.19 -0.03

## y.arma -0.19 -0.03 0.21

## y.arma -0.03 0.21 -0.13

## y.arma 0.21 -0.13 0.06

## y.arma -0.13 0.06 0.01

## y.arma 0.06 0.01 0

## y.arma 0.01 0 0.07

## y.arma 0 0.07 0.05

## y.arma 0.07 0.05 -0.08

## y.arma 0.05 -0.08 0.16

## y.arma -0.08 0.16 -0.33

## y.arma 0.16 -0.33 0.24

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1128  0.3796  0.5312  0.5879  0.7586  1.6339 
## [1] "The Rolling Window RMSE is:  0.588"
roll.win.rmse.wge(ts_nly_open.eco, horizon = 20, d = 1 )
## [1] "Please Hold For a Moment, TSWGE is processing the Rolling Window RMSE with 238 windows."
## y.arma -0.02 -0.48 0.24

## y.arma -0.48 0.24 0.17

## y.arma 0.24 0.17 -0.29

## y.arma 0.17 -0.29 0.21

## y.arma -0.29 0.21 0.22

## y.arma 0.21 0.22 -0.04

## y.arma 0.22 -0.04 0.32

## y.arma -0.04 0.32 0.26

## y.arma 0.32 0.26 0.14

## y.arma 0.26 0.14 -0.14

## y.arma 0.14 -0.14 -0.02

## y.arma -0.14 -0.02 0.42

## y.arma -0.02 0.42 -0.2

## y.arma 0.42 -0.2 0.36

## y.arma -0.2 0.36 0.09

## y.arma 0.36 0.09 -0.52

## y.arma 0.09 -0.52 0.09

## y.arma -0.52 0.09 0.43

## y.arma 0.09 0.43 -0.19

## y.arma 0.43 -0.19 0.28

## y.arma -0.19 0.28 0.03

## y.arma 0.28 0.03 0.05

## y.arma 0.03 0.05 0.08

## y.arma 0.05 0.08 0.09

## y.arma 0.08 0.09 0.02

## y.arma 0.09 0.02 -0.17

## y.arma 0.02 -0.17 0

## y.arma -0.17 0 0.03

## y.arma 0 0.03 -0.22

## y.arma 0.03 -0.22 -0.37

## y.arma -0.22 -0.37 0.08

## y.arma -0.37 0.08 0.1

## y.arma 0.08 0.1 0.08

## y.arma 0.1 0.08 -0.08

## y.arma 0.08 -0.08 0.19

## y.arma -0.08 0.19 0.33

## y.arma 0.19 0.33 0.02

## y.arma 0.33 0.02 0.12

## y.arma 0.02 0.12 -0.1

## y.arma 0.12 -0.1 -0.43

## y.arma -0.1 -0.43 -0.04

## y.arma -0.43 -0.04 -0.44

## y.arma -0.04 -0.44 -0.11

## y.arma -0.44 -0.11 0.41

## y.arma -0.11 0.41 -0.01

## y.arma 0.41 -0.01 0.16

## y.arma -0.01 0.16 0.04

## y.arma 0.16 0.04 -0.15

## y.arma 0.04 -0.15 0.16

## y.arma -0.15 0.16 0.11

## y.arma 0.16 0.11 0.01

## y.arma 0.11 0.01 -0.07

## y.arma 0.01 -0.07 -0.03

## y.arma -0.07 -0.03 -0.08

## y.arma -0.03 -0.08 -0.3

## y.arma -0.08 -0.3 -0.06

## y.arma -0.3 -0.06 -0.18

## y.arma -0.06 -0.18 -0.18

## y.arma -0.18 -0.18 -0.07

## y.arma -0.18 -0.07 -0.01

## y.arma -0.07 -0.01 -0.04

## y.arma -0.01 -0.04 0.14

## y.arma -0.04 0.14 0.08

## y.arma 0.14 0.08 -0.1

## y.arma 0.08 -0.1 -0.19

## y.arma -0.1 -0.19 0.04

## y.arma -0.19 0.04 0.27

## y.arma 0.04 0.27 -0.21

## y.arma 0.27 -0.21 -0.08

## y.arma -0.21 -0.08 -0.06

## y.arma -0.08 -0.06 -0.09

## y.arma -0.06 -0.09 -0.07

## y.arma -0.09 -0.07 -0.13

## y.arma -0.07 -0.13 -0.03

## y.arma -0.13 -0.03 0.08

## y.arma -0.03 0.08 0.1

## y.arma 0.08 0.1 0.2

## y.arma 0.1 0.2 -0.52

## y.arma 0.2 -0.52 -0.01

## y.arma -0.52 -0.01 0.01

## y.arma -0.01 0.01 -0.67

## y.arma 0.01 -0.67 0.06

## y.arma -0.67 0.06 0.18

## y.arma 0.06 0.18 0.28

## y.arma 0.18 0.28 -0.22

## y.arma 0.28 -0.22 0.4

## y.arma -0.22 0.4 0.13

## y.arma 0.4 0.13 0.29

## y.arma 0.13 0.29 -0.51

## y.arma 0.29 -0.51 0.3

## y.arma -0.51 0.3 0.03

## y.arma 0.3 0.03 -0.09

## y.arma 0.03 -0.09 0.27

## y.arma -0.09 0.27 -0.29

## y.arma 0.27 -0.29 -0.09

## y.arma -0.29 -0.09 0.24

## y.arma -0.09 0.24 -0.1

## y.arma 0.24 -0.1 0.07

## y.arma -0.1 0.07 -0.26

## y.arma 0.07 -0.26 -0.48

## y.arma -0.26 -0.48 0.1

## y.arma -0.48 0.1 -0.02

## y.arma 0.1 -0.02 0.12

## y.arma -0.02 0.12 -0.19

## y.arma 0.12 -0.19 -0.27

## y.arma -0.19 -0.27 0.31

## y.arma -0.27 0.31 0.24

## y.arma 0.31 0.24 -0.44

## y.arma 0.24 -0.44 0.06

## y.arma -0.44 0.06 -0.41

## y.arma 0.06 -0.41 0.06

## y.arma -0.41 0.06 0.46

## y.arma 0.06 0.46 0.22

## y.arma 0.46 0.22 0.06

## y.arma 0.22 0.06 0.2

## y.arma 0.06 0.2 0.23

## y.arma 0.2 0.23 0.1

## y.arma 0.23 0.1 -0.01

## y.arma 0.1 -0.01 0.12

## y.arma -0.01 0.12 0.04

## y.arma 0.12 0.04 -0.12

## y.arma 0.04 -0.12 -0.17

## y.arma -0.12 -0.17 0.24

## y.arma -0.17 0.24 -0.17

## y.arma 0.24 -0.17 0.2

## y.arma -0.17 0.2 0.45

## y.arma 0.2 0.45 0.15

## y.arma 0.45 0.15 -0.07

## y.arma 0.15 -0.07 -0.34

## y.arma -0.07 -0.34 0.21

## y.arma -0.34 0.21 -0.03

## y.arma 0.21 -0.03 -0.2

## y.arma -0.03 -0.2 0.31

## y.arma -0.2 0.31 0.05

## y.arma 0.31 0.05 -0.17

## y.arma 0.05 -0.17 -0.14

## y.arma -0.17 -0.14 0.25

## y.arma -0.14 0.25 0.08

## y.arma 0.25 0.08 0.11

## y.arma 0.08 0.11 -0.03

## y.arma 0.11 -0.03 -0.13

## y.arma -0.03 -0.13 -0.13

## y.arma -0.13 -0.13 0.1

## y.arma -0.13 0.1 -0.49

## y.arma 0.1 -0.49 0.06

## y.arma -0.49 0.06 0.32

## y.arma 0.06 0.32 -0.32

## y.arma 0.32 -0.32 -0.42

## y.arma -0.32 -0.42 0.1

## y.arma -0.42 0.1 -0.04

## y.arma 0.1 -0.04 0.17

## y.arma -0.04 0.17 0.07

## y.arma 0.17 0.07 -0.25

## y.arma 0.07 -0.25 -0.07

## y.arma -0.25 -0.07 0.08

## y.arma -0.07 0.08 -0.13

## y.arma 0.08 -0.13 0.49

## y.arma -0.13 0.49 -0.25

## y.arma 0.49 -0.25 0.11

## y.arma -0.25 0.11 -0.31

## y.arma 0.11 -0.31 0.24

## y.arma -0.31 0.24 -0.11

## y.arma 0.24 -0.11 0.01

## y.arma -0.11 0.01 0.09

## y.arma 0.01 0.09 0.06

## y.arma 0.09 0.06 0.24

## y.arma 0.06 0.24 0.3

## y.arma 0.24 0.3 0.23

## y.arma 0.3 0.23 -0.12

## y.arma 0.23 -0.12 0

## y.arma -0.12 0 0.06

## y.arma 0 0.06 0.12

## y.arma 0.06 0.12 -0.03

## y.arma 0.12 -0.03 0.19

## y.arma -0.03 0.19 0.33

## y.arma 0.19 0.33 0.15

## y.arma 0.33 0.15 0.06

## y.arma 0.15 0.06 -0.26

## y.arma 0.06 -0.26 -0.28

## y.arma -0.26 -0.28 0.23

## y.arma -0.28 0.23 0.28

## y.arma 0.23 0.28 0.21

## y.arma 0.28 0.21 0.11

## y.arma 0.21 0.11 0.26

## y.arma 0.11 0.26 0.22

## y.arma 0.26 0.22 -0.56

## y.arma 0.22 -0.56 0.02

## y.arma -0.56 0.02 0.26

## y.arma 0.02 0.26 -0.42

## y.arma 0.26 -0.42 0.06

## y.arma -0.42 0.06 0.04

## y.arma 0.06 0.04 0.3

## y.arma 0.04 0.3 0.06

## y.arma 0.3 0.06 0.01

## y.arma 0.06 0.01 0.09

## y.arma 0.01 0.09 -0.07

## y.arma 0.09 -0.07 -0.05

## y.arma -0.07 -0.05 0.12

## y.arma -0.05 0.12 -0.26

## y.arma 0.12 -0.26 -0.06

## y.arma -0.26 -0.06 0.09

## y.arma -0.06 0.09 0.02

## y.arma 0.09 0.02 -0.67

## y.arma 0.02 -0.67 -0.39

## y.arma -0.67 -0.39 0.01

## y.arma -0.39 0.01 0.29

## y.arma 0.01 0.29 0.29

## y.arma 0.29 0.29 0.06

## y.arma 0.29 0.06 0.12

## y.arma 0.06 0.12 0.29

## y.arma 0.12 0.29 -0.2

## y.arma 0.29 -0.2 -0.17

## y.arma -0.2 -0.17 -0.32

## y.arma -0.17 -0.32 -0.26

## y.arma -0.32 -0.26 -0.08

## y.arma -0.26 -0.08 -0.35

## y.arma -0.08 -0.35 -0.56

## y.arma -0.35 -0.56 -0.09

## y.arma -0.56 -0.09 0.38

## y.arma -0.09 0.38 -0.18

## y.arma 0.38 -0.18 -0.33

## y.arma -0.18 -0.33 0.25

## y.arma -0.33 0.25 0.27

## y.arma 0.25 0.27 -0.06

## y.arma 0.27 -0.06 -0.16

## y.arma -0.06 -0.16 0.1

## y.arma -0.16 0.1 -0.19

## y.arma 0.1 -0.19 -0.03

## y.arma -0.19 -0.03 0.21

## y.arma -0.03 0.21 -0.13

## y.arma 0.21 -0.13 0.06

## y.arma -0.13 0.06 0.01

## y.arma 0.06 0.01 0

## y.arma 0.01 0 0.07

## y.arma 0 0.07 0.05

## y.arma 0.07 0.05 -0.08

## y.arma 0.05 -0.08 0.16

## y.arma -0.08 0.16 -0.33

## [1] "The Summary Statistics for the Rolling Window RMSE Are:"
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##  0.1128  0.3793  0.5352  0.5887  0.7603  1.6339 
## [1] "The Rolling Window RMSE is:  0.589"
# Original Score:
# [1] "The Summary Statistics for the Rolling Window RMSE Are:"
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#  0.1128  0.3796  0.5312  0.5879  0.7586  1.6339 
# [1] "The Rolling Window RMSE is:  0.588"


# New Score:
# [1] "The Summary Statistics for the Rolling Window RMSE Are:"
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
#  0.1128  0.3796  0.5312  0.5879  0.7586  1.6339 
# [1] "The Rolling Window RMSE is:  0.588"

We can note that there was no difference at all in the RSME from the Rolling window Long horizon model with or without the additional economic factors

b. VAR with at least one explanatory variable

# Create a data frame with all four predictors (Open, Close, High, Low columns)
tnlyx <- data.frame(Open = ts(df.adj$Open), Close = ts(df.adj$Close), High = ts(df.adj$High), Low = ts(df.adj$Low), frequency = 1)

# Remove rows with NA values from the entire data frame
df_clean <- tnlyx[complete.cases(tnlyx), ]

# Apply VARSelect to select the optimal lag order
var_order <- VARselect(df_clean, lag.max = 10, type = "both")

# Get the optimal lag order selected by AIC, HQIC, and SC
optimal_lag <- var_order$selection

optimal_lag
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      1      1      1      1
# Create a data frame with all four variables (Open, Close, High, Low columns)
data <- data.frame(Open = df.adj$Open, Close = df.adj$Close, High = df.adj$High, Low = df.adj$Low)

# Set the lag order you want to use
lag_order <- 1

# Lag the other three variables (Close, High, Low) in the data frame
lagged_data <- data %>% mutate_at(vars(-Open), lag, n = lag_order)

# Remove rows with NA values from the lagged_data
lagged_data <- na.omit(lagged_data)

# Fit the VAR model using the lagged_data
var_model <- VAR(lagged_data, p = lag_order, type = "both")


var_model
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation Open: 
## ========================================= 
## Call:
## Open = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1         const 
##  0.9267299491 -0.0725082332  0.0518762053  0.0563128408  0.4193964134 
##         trend 
## -0.0001087287 
## 
## 
## Estimated coefficients for equation Close: 
## ========================================== 
## Call:
## Close = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1         const 
##  0.8957877004 -0.0129277781  0.0588175712  0.0183600471  0.4523733878 
##         trend 
## -0.0002184793 
## 
## 
## Estimated coefficients for equation High: 
## ========================================= 
## Call:
## High = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##      Open.l1     Close.l1      High.l1       Low.l1        const        trend 
##  0.940172100 -0.032746836  0.147284505 -0.074003928  0.356700949 -0.000180586 
## 
## 
## Estimated coefficients for equation Low: 
## ======================================== 
## Call:
## Low = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1         const 
##  1.0683737037 -0.1966631921 -0.0835850892  0.1845078280  0.1740256553 
##         trend 
## -0.0000982939
summary(var_model)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Open, Close, High, Low 
## Deterministic variables: both 
## Sample size: 260 
## Log Likelihood: 970.857 
## Roots of the characteristic polynomial:
## 0.9642 0.2653 0.05207 0.03593
## Call:
## VAR(y = lagged_data, p = lag_order, type = "both")
## 
## 
## Estimation results for equation Open: 
## ===================================== 
## Open = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.9267299  0.2720113   3.407 0.000764 ***
## Close.l1 -0.0725082  0.3009176  -0.241 0.809783    
## High.l1   0.0518762  0.1076667   0.482 0.630347    
## Low.l1    0.0563128  0.1215762   0.463 0.643625    
## const     0.4193964  0.2000355   2.097 0.037017 *  
## trend    -0.0001087  0.0001869  -0.582 0.561207    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.2214 on 254 degrees of freedom
## Multiple R-Squared: 0.9195,  Adjusted R-squared: 0.9179 
## F-statistic: 579.9 on 5 and 254 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Close: 
## ====================================== 
## Close = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.8957877  0.2612343   3.429 0.000707 ***
## Close.l1 -0.0129278  0.2889954  -0.045 0.964355    
## High.l1   0.0588176  0.1034010   0.569 0.569974    
## Low.l1    0.0183600  0.1167594   0.157 0.875175    
## const     0.4523734  0.1921102   2.355 0.019296 *  
## trend    -0.0002185  0.0001795  -1.217 0.224609    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.2127 on 254 degrees of freedom
## Multiple R-Squared: 0.9249,  Adjusted R-squared: 0.9234 
## F-statistic: 625.2 on 5 and 254 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation High: 
## ===================================== 
## High = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.9401721  0.1534984   6.125 3.43e-09 ***
## Close.l1 -0.0327468  0.1698105  -0.193  0.84724    
## High.l1   0.1472845  0.0607573   2.424  0.01604 *  
## Low.l1   -0.0740039  0.0686065  -1.079  0.28176    
## const     0.3567009  0.1128818   3.160  0.00177 ** 
## trend    -0.0001806  0.0001055  -1.712  0.08804 .  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.125 on 254 degrees of freedom
## Multiple R-Squared: 0.9738,  Adjusted R-squared: 0.9733 
## F-statistic:  1889 on 5 and 254 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Low: 
## ==================================== 
## Low = Open.l1 + Close.l1 + High.l1 + Low.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   1.068e+00  2.020e-01   5.289 2.65e-07 ***
## Close.l1 -1.967e-01  2.234e-01  -0.880    0.380    
## High.l1  -8.359e-02  7.995e-02  -1.045    0.297    
## Low.l1    1.845e-01  9.028e-02   2.044    0.042 *  
## const     1.740e-01  1.485e-01   1.172    0.242    
## trend    -9.829e-05  1.388e-04  -0.708    0.479    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.1644 on 254 degrees of freedom
## Multiple R-Squared: 0.9551,  Adjusted R-squared: 0.9542 
## F-statistic:  1080 on 5 and 254 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##          Open   Close    High     Low
## Open  0.04903 0.04583 0.02054 0.02844
## Close 0.04583 0.04522 0.01999 0.02817
## High  0.02054 0.01999 0.01561 0.01157
## Low   0.02844 0.02817 0.01157 0.02703
## 
## Correlation matrix of residuals:
##         Open  Close   High    Low
## Open  1.0000 0.9733 0.7423 0.7811
## Close 0.9733 1.0000 0.7525 0.8058
## High  0.7423 0.7525 1.0000 0.5631
## Low   0.7811 0.8058 0.5631 1.0000
#xtract the estimated coefficients from the var_model list
coefficients <- coef(var_model)[['Open']]  # Replace 'Open' with the desired variable

# Extract the estimated coefficients and convert to numeric format
coefficients <- as.numeric(coefficients)

# Extract the standard errors of the coefficients
standard_errors <- sqrt(diag(vcov(var_model)))

# Calculate the confidence intervals (95% by default)
lower_ci <- coefficients - 1.96 * standard_errors
upper_ci <- coefficients + 1.96 * standard_errors

# Create a data frame to store the results
confidence_intervals <- data.frame(
  Coefficients = coefficients,
  Lower_CI = lower_ci,
  Upper_CI = upper_ci
)

print(confidence_intervals)
##                    Coefficients      Lower_CI      Upper_CI
## Open:(Intercept)   0.9267299491  0.5346604061  1.3187994922
## Open:Open.l1      -0.0725082332 -0.6056503098  0.4606338434
## Open:Close.l1      0.0518762053 -0.5379222888  0.6416746994
## Open:High.l1       0.0563128408 -0.1547139621  0.2673396437
## Open:Low.l1        0.4193964134  0.1811070801  0.6576857468
## Open:trend        -0.0001087287 -0.0004750103  0.0002575530
## Close:(Intercept)  0.2720112636 -0.1045246403  0.6485471674
## Close:Open.l1      0.3009175990 -0.2111016007  0.8129367988
## Close:Close.l1     0.1076667362 -0.4587641764  0.6740976488
## Close:High.l1      0.1215761905 -0.0810898145  0.3242421955
## Close:Low.l1       0.2000354811 -0.0288129237  0.4288838859
## Close:trend        0.0001868784 -0.0001648913  0.0005386481
## High:(Intercept)   3.4069543185  3.1857059705  3.6282026666
## High:Open.l1      -0.2409571039 -0.5418139438  0.0598997360
## High:Close.l1      0.4818220291  0.1489934663  0.8146505919
## High:High.l1       0.4631897130  0.3441054016  0.5822740244
## High:Low.l1        2.0966101166  1.9621413156  2.2310789175
## High:trend        -0.5818151923 -0.5820218883 -0.5816084963
## Low:(Intercept)    0.0007635957 -0.2903701649  0.2918973564
## Low:Open.l1        0.8097827491  0.4138946714  1.2056708268
## Low:Close.l1       0.6303472613  0.1923885964  1.0683059262
## Low:High.l1        0.6436250086  0.4869256989  0.8003243182
## Low:Low.l1         0.0370173831 -0.1399258939  0.2139606600
## Low:trend          0.5612071811  0.5609351963  0.5614791659

Observations

Estimated coefficients for equation Open:

** A one-unit increase in the lagged ‘Open’ variable (Open[t-1]) leads to a 0.9267 increase in the current ‘Open’ variable (Open[t]).

** A one-unit increase in the lagged ‘Close’ variable (Close[t-1]) leads to a -0.0725 decrease in the current ‘Open’ variable (Open[t]).

**A one-unit increase in the lagged ‘High’ variable (High[t-1]) leads to a 0.0519 increase in the current ‘Open’ variable (Open[t]).

**A one-unit increase in the lagged ‘Low’ variable (Low[t-1]) leads to a 0.0563 increase in the current ‘Open’ variable (Open[t]).

The constant term (intercept) and trend do not have lagged values as they are constant across time.

The equation’s multiple R-squared and adjusted R-squared are 0.9195 and 0.9179, respectively, indicating a good fit.

The F-statistic and its p-value suggest that the overall equation is significant.

# Fit the VAR model using the lagged_data

VAR_SM2 = VAR(lagged_data,lag.max = 5, type = "both")

pred.short = predict(VAR_SM2,n.ahead = 12)
pred.short$fcst$Open[,1]
##  [1]  9.970557  9.984902  9.998284 10.010942 10.023007 10.034528 10.045531
##  [8] 10.056037 10.066064 10.075630 10.084750 10.093442
plot(data$Open, type = "l")
lines(seq(251,262,1),pred.short$fcst$Open[,1],col = "red")

var_ase_short_horizon = mean((data$Open[251:262] - pred.short$fcst$Open[,1])^2)

var_ase_short_horizon
## [1] 0.06697107
# Fit the VAR model using the lagged_data

VAR_SM2 = VAR(lagged_data,lag.max = 15, type = "both")

pred.long = predict(VAR_SM2,n.ahead = 20)
pred.long$fcst$Open[,1]
##  [1]  9.970557  9.984902  9.998284 10.010942 10.023007 10.034528 10.045531
##  [8] 10.056037 10.066064 10.075630 10.084750 10.093442 10.101720 10.109599
## [15] 10.117093 10.124217 10.130983 10.137405 10.143494 10.149263
plot(data$Open, type = "l")
lines(seq(243,262,1),pred.long$fcst$Open[,1],col = "red")

var_ase_long_horizon = mean((data$Open[243:262] - pred.long$fcst$Open[,1])^2)

var_ase_long_horizon 
## [1] 0.1551258

b PT II Make supplemental model with addtional economic features

# Create a data frame with all four predictors (Open, Close, High, Low columns)
tnlyx.eco <- data.frame(Open = ts(finaldata$Open), Close = ts(finaldata$Close), High = ts(finaldata$High), Low = ts(finaldata$Low), CPI = ts(finaldata$CPI_Score), Morg = ts(finaldata$MORTGAGE30US), frequency = 1)

# Remove rows with NA values from the entire data frame
df_clean.eco <- tnlyx.eco[complete.cases(tnlyx.eco), ]

# Apply VARSelect to select the optimal lag order
var_order.eco <- VARselect(df_clean.eco, lag.max = 10, type = "both")

# Get the optimal lag order selected by AIC, HQIC, and SC
optimal_lag.eco <- var_order.eco$selection

optimal_lag.eco
## AIC(n)  HQ(n)  SC(n) FPE(n) 
##      3      1      1      3

It’s interesting to not that the ideal model is still looking at a lag 1 model from both the HQIC & SC criterion, however with the additional economic features added both the AIC & FPE are suggesting an optimal lag order of 3.

# Create a data frame with all six variables (Open, Close, High, Low, CPI Score, Monthly Mortgage Rate columns)
data.eco <- data.frame(Open = finaldata$Open, Close = finaldata$Close, High = finaldata$High, Low = finaldata$Low,  Cpi = finaldata$CPI_Score, Morg = finaldata$MORTGAGE30US)

# Set the lag order you want to use, we will still use optimal lag order of 1 rather than suggested at 3
lag_order <- 1

# Lag the other three variables (Close, High, Low) in the data frame
lagged_data.eco <- data.eco %>% mutate_at(vars(-Open), lag, n = lag_order)

# Remove rows with NA values from the lagged_data
lagged_data.eco <- na.omit(lagged_data.eco)

# Fit the VAR model using the lagged_data
var_model.eco <- VAR(lagged_data.eco, p = lag_order, type = "both")


var_model.eco
## 
## VAR Estimation Results:
## ======================= 
## 
## Estimated coefficients for equation Open: 
## ========================================= 
## Call:
## Open = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1        Cpi.l1 
##  0.9199181459 -0.0697147839  0.0494788754  0.0684517737 -0.0048785930 
##       Morg.l1         const         trend 
##  0.0541031352  1.2845817216  0.0001719648 
## 
## 
## Estimated coefficients for equation Close: 
## ========================================== 
## Call:
## Close = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##      Open.l1     Close.l1      High.l1       Low.l1       Cpi.l1      Morg.l1 
##  0.892297516 -0.014609455  0.055702867  0.033061355 -0.005939828  0.051638085 
##        const        trend 
##  1.567338587  0.000136305 
## 
## 
## Estimated coefficients for equation High: 
## ========================================= 
## Call:
## High = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1        Cpi.l1 
##  0.9419165019 -0.0455695840  0.1404127191 -0.0440088704 -0.0121763466 
##       Morg.l1         const         trend 
##  0.0789380537  2.7593275606  0.0005723216 
## 
## 
## Estimated coefficients for equation Low: 
## ======================================== 
## Call:
## Low = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1        Cpi.l1 
##  1.0552822336 -0.1765185131 -0.0781046211  0.1666980653  0.0073008711 
##       Morg.l1         const         trend 
## -0.0078037101 -1.4414927715 -0.0005927528 
## 
## 
## Estimated coefficients for equation Cpi: 
## ======================================== 
## Call:
## Cpi = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##      Open.l1     Close.l1      High.l1       Low.l1       Cpi.l1      Morg.l1 
## -0.026034978  0.089520361  0.078944546 -0.087146208  0.950286092  0.241467622 
##        const        trend 
## 10.054341812  0.003314133 
## 
## 
## Estimated coefficients for equation Morg: 
## ========================================= 
## Call:
## Morg = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##       Open.l1      Close.l1       High.l1        Low.l1        Cpi.l1 
##  0.0519922684 -0.1566944448  0.0432570834  0.0494048119  0.0044952797 
##       Morg.l1         const         trend 
##  0.9771518634 -0.8346091457 -0.0001934743
summary(var_model.eco)
## 
## VAR Estimation Results:
## ========================= 
## Endogenous variables: Open, Close, High, Low, Cpi, Morg 
## Deterministic variables: both 
## Sample size: 259 
## Log Likelihood: 1328.41 
## Roots of the characteristic polynomial:
## 0.9968 0.9475 0.9475 0.2369 0.05038 0.03913
## Call:
## VAR(y = lagged_data.eco, p = lag_order, type = "both")
## 
## 
## Estimation results for equation Open: 
## ===================================== 
## Open = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.9199181  0.2737873   3.360 0.000901 ***
## Close.l1 -0.0697148  0.3034541  -0.230 0.818483    
## High.l1   0.0494789  0.1083410   0.457 0.648285    
## Low.l1    0.0684518  0.1253812   0.546 0.585586    
## Cpi.l1   -0.0048786  0.0116480  -0.419 0.675696    
## Morg.l1   0.0541031  0.0653211   0.828 0.408308    
## const     1.2845817  2.4234768   0.530 0.596541    
## trend     0.0001720  0.0007634   0.225 0.821949    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.2224 on 251 degrees of freedom
## Multiple R-Squared: 0.9194,  Adjusted R-squared: 0.9171 
## F-statistic:   409 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Close: 
## ====================================== 
## Close = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.8922975  0.2629871   3.393 0.000803 ***
## Close.l1 -0.0146095  0.2914835  -0.050 0.960066    
## High.l1   0.0557029  0.1040672   0.535 0.592945    
## Low.l1    0.0330614  0.1204352   0.275 0.783914    
## Cpi.l1   -0.0059398  0.0111885  -0.531 0.595968    
## Morg.l1   0.0516381  0.0627444   0.823 0.411294    
## const     1.5673386  2.3278763   0.673 0.501382    
## trend     0.0001363  0.0007332   0.186 0.852679    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.2136 on 251 degrees of freedom
## Multiple R-Squared: 0.9247,  Adjusted R-squared: 0.9227 
## F-statistic: 440.6 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation High: 
## ===================================== 
## High = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.9419165  0.1531482   6.150 3.03e-09 ***
## Close.l1 -0.0455696  0.1697429  -0.268   0.7886    
## High.l1   0.1404127  0.0606026   2.317   0.0213 *  
## Low.l1   -0.0440089  0.0701344  -0.627   0.5309    
## Cpi.l1   -0.0121763  0.0065156  -1.869   0.0628 .  
## Morg.l1   0.0789381  0.0365386   2.160   0.0317 *  
## const     2.7593276  1.3556183   2.035   0.0429 *  
## trend     0.0005723  0.0004270   1.340   0.1813    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.1244 on 251 degrees of freedom
## Multiple R-Squared: 0.9742,  Adjusted R-squared: 0.9735 
## F-statistic:  1355 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Low: 
## ==================================== 
## Low = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   1.0552822  0.2030237   5.198 4.18e-07 ***
## Close.l1 -0.1765185  0.2250227  -0.784   0.4335    
## High.l1  -0.0781046  0.0803389  -0.972   0.3319    
## Low.l1    0.1666981  0.0929749   1.793   0.0742 .  
## Cpi.l1    0.0073009  0.0086375   0.845   0.3988    
## Morg.l1  -0.0078037  0.0484381  -0.161   0.8721    
## const    -1.4414928  1.7971001  -0.802   0.4232    
## trend    -0.0005928  0.0005661  -1.047   0.2960    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.1649 on 251 degrees of freedom
## Multiple R-Squared: 0.9552,  Adjusted R-squared: 0.954 
## F-statistic: 765.1 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Cpi: 
## ==================================== 
## Cpi = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##           Estimate Std. Error t value Pr(>|t|)    
## Open.l1  -0.026035   0.439065  -0.059  0.95276    
## Close.l1  0.089520   0.486641   0.184  0.85420    
## High.l1   0.078945   0.173743   0.454  0.64995    
## Low.l1   -0.087146   0.201070  -0.433  0.66509    
## Cpi.l1    0.950286   0.018680  50.873  < 2e-16 ***
## Morg.l1   0.241468   0.104754   2.305  0.02198 *  
## const    10.054342   3.886460   2.587  0.01024 *  
## trend     0.003314   0.001224   2.707  0.00725 ** 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.3566 on 251 degrees of freedom
## Multiple R-Squared: 0.9959,  Adjusted R-squared: 0.9958 
## F-statistic:  8752 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## Estimation results for equation Morg: 
## ===================================== 
## Morg = Open.l1 + Close.l1 + High.l1 + Low.l1 + Cpi.l1 + Morg.l1 + const + trend 
## 
##            Estimate Std. Error t value Pr(>|t|)    
## Open.l1   0.0519923  0.0538543   0.965  0.33526    
## Close.l1 -0.1566944  0.0596898  -2.625  0.00919 ** 
## High.l1   0.0432571  0.0213108   2.030  0.04343 *  
## Low.l1    0.0494048  0.0246626   2.003  0.04623 *  
## Cpi.l1    0.0044953  0.0022912   1.962  0.05087 .  
## Morg.l1   0.9771519  0.0128488  76.050  < 2e-16 ***
## const    -0.8346091  0.4767009  -1.751  0.08120 .  
## trend    -0.0001935  0.0001502  -1.289  0.19875    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## 
## Residual standard error: 0.04374 on 251 degrees of freedom
## Multiple R-Squared: 0.9839,  Adjusted R-squared: 0.9834 
## F-statistic:  2186 on 7 and 251 DF,  p-value: < 2.2e-16 
## 
## 
## 
## Covariance matrix of residuals:
##            Open     Close       High        Low       Cpi       Morg
## Open   0.049450  0.046231  0.0205802  0.0287639 -0.001456 -0.0011934
## Close  0.046231  0.045625  0.0200324  0.0285248 -0.001350 -0.0011136
## High   0.020580  0.020032  0.0154725  0.0117992 -0.003395 -0.0006113
## Low    0.028764  0.028525  0.0117992  0.0271913 -0.001470 -0.0005077
## Cpi   -0.001456 -0.001350 -0.0033946 -0.0014701  0.127173 -0.0018364
## Morg  -0.001193 -0.001114 -0.0006113 -0.0005077 -0.001836  0.0019133
## 
## Correlation matrix of residuals:
##           Open    Close     High      Low      Cpi     Morg
## Open   1.00000  0.97331  0.74403  0.78442 -0.01836 -0.12269
## Close  0.97331  1.00000  0.75396  0.80985 -0.01773 -0.11919
## High   0.74403  0.75396  1.00000  0.57525 -0.07653 -0.11235
## Low    0.78442  0.80985  0.57525  1.00000 -0.02500 -0.07038
## Cpi   -0.01836 -0.01773 -0.07653 -0.02500  1.00000 -0.11773
## Morg  -0.12269 -0.11919 -0.11235 -0.07038 -0.11773  1.00000

The R-squared and Adjusted R-squared values provide a measure of how well the model fits the data. It indicates the proportion of variance in the target variable that is explained by the independent variables. For example, in the equation for “Open,” the R-squared value is approximately 0.9194, indicating that about 91.94% of the variation in “Open” can be explained by the lagged values of all variables.

The F-statistic tests the overall significance of the model. It assesses whether at least one of the independent variables has a statistically significant impact on the dependent variable. For instance, in the equation for “Open,” the F-statistic is 409, and the p-value is virtually zero (p-value: < 2.2e-16). This indicates that the overall model is highly significant.

Overall, the VAR model results show that several lagged variables have significant effects on each target variable (Open, Close, High, Low, Cpi, Morg), indicating dynamic relationships among the variables in the system. Make sure to validate the model assumptions, such as the independence and normality of residuals, to ensure the model’s reliability. It is important to note that only lag 1 of “Open” is the only statistically significant feature contained in the model.

# Extract the estimated coefficients from the var_model list
coefficients.eco <- coef(var_model.eco)[['Open']]  # Replace 'Open' with the desired variable
coefficients.eco
##               Estimate   Std. Error    t value    Pr(>|t|)
## Open.l1   0.9199181459 0.2737873451  3.3599732 0.000900853
## Close.l1 -0.0697147839 0.3034540750 -0.2297375 0.818482851
## High.l1   0.0494788754 0.1083409576  0.4566959 0.648284573
## Low.l1    0.0684517737 0.1253811764  0.5459494 0.585585641
## Cpi.l1   -0.0048785930 0.0116480371 -0.4188339 0.675695694
## Morg.l1   0.0541031352 0.0653211450  0.8282637 0.408308015
## const     1.2845817216 2.4234767986  0.5300574 0.596540734
## trend     0.0001719648 0.0007633562  0.2252746 0.821948969
# Extract the p-values of the coefficients
p_values.eco <- summary(var_model.eco)$Open$p.value  # Replace 'Open' with the desired variable

# Check the significance of coefficients (optional)
print(p_values.eco)
## NULL
# Extract the estimated coefficients and convert to numeric format
coefficients.eco <- as.numeric(coefficients.eco)

# Extract the standard errors of the coefficients
standard_errors.eco <- sqrt(diag(vcov(var_model.eco)))

# Filter out non-significant coefficients
significant_indices <- p_values.eco <= 0.05
coefficients.eco <- coefficients.eco[significant_indices]
standard_errors.eco <- standard_errors.eco[significant_indices]

# Calculate the confidence intervals (95% by default) for significant coefficients
lower_ci.eco <- coefficients.eco - 1.96 * standard_errors.eco
upper_ci.eco <- coefficients.eco + 1.96 * standard_errors.eco


# Create a data frame to store the results
confidence_intervals.eco <- data.frame(
  Coefficients.eco = coefficients.eco,
  Lower_CI.eco = lower_ci.eco,
  Upper_CI.eco = upper_ci.eco
)

print(confidence_intervals.eco)
## [1] Coefficients.eco Lower_CI.eco     Upper_CI.eco    
## <0 rows> (or 0-length row.names)
print(p_values.eco)
## NULL
# Fit the VAR model using the lagged_data

VAR_SM2.eco = VAR(lagged_data.eco,lag.max = 5, type = "both")

pred.short.eco = predict(VAR_SM2.eco,n.ahead = 12)
pred.short.eco$fcst$Open[,1]
##  [1]  9.997905 10.051699 10.111398 10.167951 10.222868 10.275086 10.323564
##  [8] 10.368556 10.410470 10.449502 10.485816 10.519600
plot(data.eco$Open, type = "l")
lines(seq(250,261,1),pred.short$fcst$Open[,1],col = "red")

var_ase_short_horizon.eco = mean((data.eco$Open[250:261] - pred.short.eco$fcst$Open[,1])^2)

var_ase_short_horizon.eco
## [1] 0.2019013
# Fit the VAR model using the lagged_data

VAR_SM2.eco = VAR(lagged_data.eco,lag.max = 15, type = "both")

pred.long.eco = predict(VAR_SM2.eco,n.ahead = 20)
pred.long.eco$fcst$Open[,1]
##  [1]  9.997905 10.051699 10.111398 10.167951 10.222868 10.275086 10.323564
##  [8] 10.368556 10.410470 10.449502 10.485816 10.519600 10.551043 10.580318
## [15] 10.607587 10.633001 10.656701 10.678819 10.699474 10.718779
plot(data.eco$Open, type = "l")
lines(seq(242,261,1),pred.long.eco$fcst$Open[,1],col = "red")

var_ase_long_horizon.eco = mean((data.eco$Open[242:261] - pred.long$fcst$Open[,1])^2)

var_ase_long_horizon.eco 
## [1] 0.16422

c. Neural Network (mlp) - short horizon

#MLP

NLYsmall = df.adj[1:250,]
NLYsmallDF = data.frame(Close = ts(NLYsmall$Close), High = ts(NLYsmall$High), Low = ts(NLYsmall$Low))

#Using forecast Open
fit.mlp.Close = mlp(ts(NLYsmallDF$Close),reps = 50, comb = "mean")
fit.mlp.High = mlp(ts(NLYsmallDF$High),reps = 50, comb = "mean")
fit.mlp.Low = mlp(ts(NLYsmallDF$Low),reps = 50, comb = "mean")

#Forecast the explainble features
fore.mlp.Close = forecast(fit.mlp.Close, h = 12)
fore.mlp.High = forecast(fit.mlp.High, h = 12)
fore.mlp.Low = forecast(fit.mlp.Low, h = 12)


#plot(fore.mlp.Open) # plot the forecasts

NLYsmallDF_fore = data.frame(Close = ts(fore.mlp.Close$mean), High = ts(fore.mlp.High$mean), Low = ts(fore.mlp.Low$mean))
NLYsmallDF_fore
##         Close     High      Low
## t+1  10.50384 10.77509 10.43800
## t+2  10.52037 10.75983 10.43602
## t+3  10.50798 10.75668 10.43408
## t+4  10.50913 10.75586 10.43217
## t+5  10.51536 10.75123 10.43029
## t+6  10.51737 10.74645 10.42844
## t+7  10.51895 10.74213 10.42662
## t+8  10.52174 10.73772 10.42484
## t+9  10.52485 10.73323 10.42309
## t+10 10.52771 10.72864 10.42136
## t+11 10.53048 10.72390 10.41967
## t+12 10.53348 10.71908 10.41800
fit.mlp = mlp(ts(NLYsmall$Open),reps = 50,comb = "mean",hd.auto.type = "cv",xreg = NLYsmallDF) #sensitive to initial values, first 50 iterations

fit.mlp
## MLP fit with 7 hidden nodes and 50 repetitions.
## Univariate lags: (2,3)
## 3 regressors included.
## - Regressor 1 lags: (1,2)
## - Regressor 2 lags: (3)
## - Regressor 3 lags: (2)
## Forecast combined using the mean operator.
## MSE: 0.0026.
plot(fit.mlp)

NLYDF = data.frame(Close = ts(c(NLYsmallDF$Close,NLYsmallDF_fore$Close)), High = ts(c(NLYsmallDF$High, NLYsmallDF_fore$High)),Low = ts(c(NLYsmallDF$Low, NLYsmallDF_fore$Low)))


fore.mlp.short = forecast(fit.mlp, h = 12, xreg = NLYDF)
plot(fore.mlp.short)

plot(df.adj$Open, type = "l")
lines(seq(251,262,1),fore.mlp.short$mean,col = "blue")

MLP_SH_ASE = mean((df.adj$Open[251:262] - fore.mlp.short$mean)^2)
print(paste("ASE Score:", MLP_SH_ASE))
## [1] "ASE Score: 0.24970451814011"

c. Neural Network (mlp) - Long horizon

#MLP

NLYLong = df.adj[1:243,]
NLYLongDF = data.frame(Close = ts(NLYLong$Close), High = ts(NLYLong$High), Low = ts(NLYLong$Low))

#Using forecast Open
fit.mlp.Close = mlp(ts(NLYLongDF$Close), hd.auto.type = "cv",reps = 50, comb = "mean")
fit.mlp.High = mlp(ts(NLYLongDF$High), hd.auto.type = "cv",reps = 50, comb = "mean")
fit.mlp.Low = mlp(ts(NLYLongDF$Low), hd.auto.type = "cv",reps = 50, comb = "mean")

#Forecast the explainable features
fore.mlp.Close = forecast(fit.mlp.Close, h = 20)
fore.mlp.High = forecast(fit.mlp.High, h = 20)
fore.mlp.Low = forecast(fit.mlp.Low, h = 20)


#plot(fore.mlp.Open) # plot the forecasts

NLYLongDF_fore = data.frame(Close = ts(fore.mlp.Close$mean), High = ts(fore.mlp.High$mean), Low = ts(fore.mlp.Low$mean))

NLYLongDF_fore
##         Close     High      Low
## t+1  10.52282 10.45923 10.32672
## t+2  10.50425 10.44895 10.32348
## t+3  10.50724 10.43844 10.32027
## t+4  10.50509 10.42558 10.31709
## t+5  10.49757 10.41616 10.31395
## t+6  10.49294 10.40806 10.31084
## t+7  10.48778 10.39989 10.30776
## t+8  10.48195 10.39227 10.30471
## t+9  10.47654 10.38526 10.30169
## t+10 10.47112 10.37861 10.29869
## t+11 10.46565 10.37235 10.29572
## t+12 10.46029 10.36648 10.29277
## t+13 10.45498 10.36098 10.28985
## t+14 10.44972 10.35583 10.28695
## t+15 10.44454 10.35101 10.28407
## t+16 10.43943 10.34652 10.28122
## t+17 10.43439 10.34233 10.27839
## t+18 10.42944 10.33843 10.27559
## t+19 10.42456 10.33480 10.27282
## t+20 10.41977 10.33143 10.27007
fit.mlp = mlp(ts(NLYLong$Open),reps = 50,comb = "mean",hd.auto.type = "cv",xreg = NLYLongDF) #sensitive to initial values, first 50 iterations

fit.mlp
## MLP fit with 7 hidden nodes and 50 repetitions.
## Univariate lags: (1,2,3,4)
## 1 regressor included.
## - Regressor 1 lags: (1)
## Forecast combined using the mean operator.
## MSE: 0.0027.
plot(fit.mlp)

NLYDF.Long = data.frame(Close = ts(c(NLYLongDF$Close,NLYLongDF_fore$Close)), High = ts(c(NLYLongDF$High, NLYLongDF_fore$High)),Low = ts(c(NLYLongDF$Low, NLYLongDF_fore$Low)))


fore.mlp.long = forecast(fit.mlp, h = 20, xreg = NLYDF.Long)
plot(fore.mlp.long)

plot(df.adj$Open, type = "l")
lines(seq(243,262,1),fore.mlp.long$mean,col = "blue")

MLP_LH_ASE = mean((df.adj$Open[243:262] - fore.mlp.long$mean)^2)
print(paste("ASE Score:", MLP_LH_ASE))
## [1] "ASE Score: 0.114037904415089"

c. Neural Network (mlp) - short horizon Environmental Features

#MLP

NLYsmall.eco = finaldata[1:250,]
NLYsmallDF.eco = data.frame(Close = ts(NLYsmall.eco$Close), High = ts(NLYsmall.eco$High), Low = ts(NLYsmall.eco$Low), CPI = ts(NLYsmall.eco$CPI_Score), Morg = ts(NLYsmall.eco$MORTGAGE30US))

#Using forecast Open
fit.mlp.Close.eco = mlp(ts(NLYsmall.eco$Close),reps = 50, comb = "mean")
fit.mlp.High.eco = mlp(ts(NLYsmall.eco$High),reps = 50, comb = "mean")
fit.mlp.Low.eco = mlp(ts(NLYsmall.eco$Low),reps = 50, comb = "mean")
fit.mlp.CPI.eco = mlp(ts(NLYsmall.eco$CPI_Score),  reps = 50, comb = "mean")
fit.mlp.Morg.eco = mlp(ts(NLYsmall.eco$MORTGAGE30US), reps = 50, comb = "mean")

#Forecast the explainable features
fore.mlp.Close.eco = forecast(fit.mlp.Close.eco, h = 12)
fore.mlp.High.eco = forecast(fit.mlp.High.eco, h = 12)
fore.mlp.Low.eco = forecast(fit.mlp.Low.eco, h = 12)
fore.mlp.CPI.eco = forecast(fit.mlp.CPI.eco, h = 12)
fore.mlp.Morg.eco = forecast(fit.mlp.Morg.eco, h = 12)

#plot(fore.mlp.Open) # plot the forecasts

NLYsmallDF_fore.eco = data.frame(Close = ts(fore.mlp.Close.eco$mean), 
                                 High = ts(fore.mlp.High.eco$mean), 
                                 Low = ts(fore.mlp.Low.eco$mean), 
                                 CPI =ts(fore.mlp.CPI.eco$mean), 
                                 Morg = ts(fore.mlp.Morg.eco$mean))

NLYsmallDF_fore.eco
##         Close     High      Low      CPI     Morg
## t+1  10.50488 10.77812 10.43837 252.4983 4.539445
## t+2  10.52020 10.76670 10.43676 252.5577 4.550443
## t+3  10.50576 10.76732 10.43515 252.6170 4.565469
## t+4  10.50576 10.76966 10.43355 252.8141 4.572542
## t+5  10.51314 10.76791 10.43197 252.8996 4.572679
## t+6  10.51318 10.76645 10.43040 252.9851 4.572563
## t+7  10.51212 10.76565 10.42886 253.0705 4.571883
## t+8  10.51413 10.76451 10.42732 253.2568 4.570938
## t+9  10.51681 10.76323 10.42581 253.3594 4.572390
## t+10 10.51697 10.76198 10.42432 253.4619 4.577478
## t+11 10.51726 10.76068 10.42285 253.5644 4.583795
## t+12 10.51922 10.75930 10.42139 253.7384 4.588483
fit.mlp.eco = mlp(ts(NLYsmall.eco$Open),reps = 50,comb = "mean",hd.auto.type = "cv",xreg = NLYsmallDF.eco) #sensitive to initial values, first 50 iterations

fit.mlp.eco
## MLP fit with 8 hidden nodes and 50 repetitions.
## Univariate lags: (2,3)
## 4 regressors included.
## - Regressor 1 lags: (1,2,3)
## - Regressor 2 lags: (3)
## - Regressor 3 lags: (2)
## - Regressor 4 lags: (2)
## Forecast combined using the mean operator.
## MSE: 0.0023.
plot(fit.mlp.eco)

NLYDF.eco = data.frame(Close = ts(c(NLYsmallDF.eco$Close,NLYsmallDF_fore.eco$Close)), 
                       High = ts(c(NLYsmallDF.eco$High, NLYsmallDF_fore.eco$High)),
                       Low = ts(c(NLYsmallDF.eco$Low, NLYsmallDF_fore.eco$Low)), 
                       CPI = ts(c(NLYsmallDF.eco$CPI, NLYsmallDF_fore.eco$CPI)), 
                       Morg = ts(c(NLYsmallDF.eco$Morg, NLYsmallDF_fore.eco$Morg)))


fore.mlp.short.eco = forecast(fit.mlp.eco, h = 12, xreg = NLYDF.eco)
plot(fore.mlp.short.eco)

plot(finaldata$Open, type = "l")
lines(seq(250,261,1),fore.mlp.short.eco$mean,col = "blue")

MLP_SH_ASE.eco = mean((finaldata$Open[250:261] - fore.mlp.short.eco$mean)^2)
print(paste("ASE Score:", MLP_SH_ASE.eco))
## [1] "ASE Score: 0.229534963042687"

c. Neural Network (mlp) - Long horizon Environmental Features

#MLP

NLYLong.eco = finaldata[1:243,]
NLYLongDF.eco = data.frame(Close = ts(NLYLong.eco$Close), 
                           High = ts(NLYLong.eco$High), 
                           Low = ts(NLYLong.eco$Low), 
                           CPI = ts(NLYLong.eco$CPI_Score), 
                           Morg = ts(NLYLong.eco$MORTGAGE30US))

#Using forecast Open
fit.mlp.Close.eco = mlp(ts(NLYLongDF.eco$Close), hd.auto.type = "cv",reps = 50, comb = "mean")
fit.mlp.High.eco = mlp(ts(NLYLongDF.eco$High), hd.auto.type = "cv",reps = 50, comb = "mean")
fit.mlp.Low.eco = mlp(ts(NLYLongDF.eco$Low), hd.auto.type = "cv",reps = 50, comb = "mean")
fit.mlp.CPI.eco = mlp(ts(NLYLongDF.eco$CPI), hd.auto.type = "cv", reps = 50, comb = "mean")
fit.mlp.Morg.eco = mlp(ts(NLYLongDF.eco$Morg), hd.auto.type = "cv", reps = 50, comb = "mean")

#Forecast the explainable features
# Update the forecast horizon to h + forecast horizon
forecast_horizon <- 20

# Forecast the explanatory variables first
fore.mlp.Close.eco <- forecast(fit.mlp.Close.eco, h = forecast_horizon)
fore.mlp.High.eco <- forecast(fit.mlp.High.eco, h = forecast_horizon)
fore.mlp.Low.eco <- forecast(fit.mlp.Low.eco, h = forecast_horizon)
fore.mlp.CPI.eco <- forecast(fit.mlp.CPI.eco, h = forecast_horizon)
fore.mlp.Morg.eco <- forecast(fit.mlp.Morg.eco, h = forecast_horizon)

# Create a data frame with the forecasted values of the explanatory variables
NLYDF.Long.eco_forecasted <- data.frame(
  Close = ts(fore.mlp.Close.eco$mean),
  High = ts(fore.mlp.High.eco$mean),
  Low = ts(fore.mlp.Low.eco$mean),
  CPI = ts(fore.mlp.CPI.eco$mean),
  Morg = ts(fore.mlp.Morg.eco$mean)
)

# Combine the historical and forecasted explanatory variables
NLYDF.Long.eco_combined <- data.frame(
  Close = ts(c(NLYLongDF.eco$Close, NLYDF.Long.eco_forecasted$Close)),
  High = ts(c(NLYLongDF.eco$High, NLYDF.Long.eco_forecasted$High)),
  Low = ts(c(NLYLongDF.eco$Low, NLYDF.Long.eco_forecasted$Low)),
  CPI = ts(c(NLYLongDF.eco$CPI, NLYDF.Long.eco_forecasted$CPI)),
  Morg = ts(c(NLYLongDF.eco$Morg, NLYDF.Long.eco_forecasted$Morg))
)

# Fit the MLP model with the combined explanatory variables
fit.mlp.eco <- mlp(ts(NLYLong.eco$Open), reps = 50, comb = "mean", hd.auto.type = "cv", xreg = NLYDF.Long.eco_combined)

fit.mlp.eco
## MLP fit with 9 hidden nodes and 50 repetitions.
## Univariate lags: (2,3)
## 4 regressors included.
## - Regressor 1 lags: (1,2,3)
## - Regressor 2 lags: (3)
## - Regressor 3 lags: (2)
## - Regressor 4 lags: (3)
## Forecast combined using the mean operator.
## MSE: 0.0023.
plot(fit.mlp.eco)

# Check the length of the updated xreg variable
length_xreg_updated <- nrow(NLYDF.Long.eco_combined)
print(length_xreg_updated)
## [1] 263
# Proceed with the forecast
fore.mlp.long.eco <- forecast(fit.mlp.eco, h = forecast_horizon, xreg = NLYDF.Long.eco_combined)


fore.mlp.long.eco
##     Point Forecast
## 244       10.52991
## 245       10.53678
## 246       10.51291
## 247       10.50953
## 248       10.51040
## 249       10.50401
## 250       10.49961
## 251       10.49391
## 252       10.48858
## 253       10.48363
## 254       10.47849
## 255       10.47318
## 256       10.46824
## 257       10.46330
## 258       10.45826
## 259       10.45332
## 260       10.44861
## 261       10.44393
## 262       10.43918
## 263       10.43455
plot(fore.mlp.long.eco)

plot(finaldata$Open, type = "l")
lines(seq(242,261,1),fore.mlp.long.eco$mean,col = "blue")

MLP_LH_ASE.eco = mean((finaldata$Open[242:261] - fore.mlp.long.eco$mean)^2)
print(paste("ASE Score:", MLP_LH_ASE.eco))
## [1] "ASE Score: 0.10655882823882"

d. Ensemble model using at least two of the above. (this model does not have to “beat” your other models.

#Original Data
sh_ensemble = (fore.mlp.short$mean + pred.short$fcst$Open[,1])/2

plot(df.adj$Open, type = "l")
lines(seq(251,262,1),sh_ensemble,col = "green")

lh_ensemble = (fore.mlp.long$mean + pred.long$fcst$Open[,1])/2

plot(df.adj$Open, type = "l")
lines(seq(243,262,1),lh_ensemble,col = "green")

# New Data
sh_ensemble.eco = (fore.mlp.short.eco$mean + pred.short.eco$fcst$Open[,1])/2

plot(df.adj$Open, type = "l")
lines(seq(250,261,1),sh_ensemble.eco,col = "green")

lh_ensemble.eco = (fore.mlp.long.eco$mean + pred.long.eco$fcst$Open[,1])/2

plot(finaldata$Open, type = "l")
lines(seq(242,261,1),lh_ensemble.eco,col = "green")

# Original ASE Scores
ensemble_SH_ASE = mean((ts_nly_open[251:262] - sh_ensemble)^2)
ensemble_SH_ASE
## [1] 0.1000075
ensemble_LH_ASE = mean((ts_nly_open[243:262] - lh_ensemble)^2)
ensemble_LH_ASE
## [1] 0.09386686
# New ASE Scores
ensemble_SH_ASE.eco = mean((ts_nly_open.eco[250:261] - sh_ensemble.eco)^2)
ensemble_SH_ASE.eco
## [1] 0.1943666
ensemble_LH_ASE.eco = mean((ts_nly_open.eco[242:261] - lh_ensemble.eco)^2)
ensemble_LH_ASE.eco
## [1] 0.1620551

The ensemble does perform better than the Univariate and the MLP models by themselves. It may be worth noting to perform an ensemble model on an ongoing basis.

The new model with the additional economic features vastly under performs in an emesmble approach compared to the original pure stock data.

5. Pick a short and long term forecast horizon based on your “problem” from part 3 and compare all models with the ASE and the rolling window ASE for both the short and long term forecasts … this does not mean you have to choose the model with the lowest ASE.

### Univariate ASEs ###

aic_uni_sh = ase_aic_univariate.short # 0.3818423
aic_uni_lh = ase_aic_univariate.long # 

aic_uni_sh.eco = ase_aic_univariate.short # 
aic_uni_lh.eco = ase_aic_univariate.long # 

bic_uni_sh = ase_bic_univariate.short # [1] 0.3891917
bic_uni_lh = ase_bic_univariate.long # 

bic_uni_sh.eco = ase_bic_univariate.short.eco # 
bic_uni_lh.eco = ase_bic_univariate.long.eco # 

roll_win_ase_short = 0.459
roll_win_ase_long = 0.588

# roll.win.rmse.wge(ts_nly_open, horizon = 12, d = 1 )

# [1] "The Summary Statistics for the Rolling Window RMSE Are:"
#    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
# 0.08954 0.27891 0.40805 0.45852 0.60149 1.49417 
# [1] "The Rolling Window RMSE is:  0.459"


### Multivariate Long Short Horizon ###
var_lh = var_ase_long_horizon
var_sh = var_ase_short_horizon

var_lh.eco = var_ase_long_horizon.eco
var_sh.eco = var_ase_short_horizon.eco

mlp_lh = MLP_LH_ASE
mlp_sh = MLP_SH_ASE

mlp_lh.eco = MLP_LH_ASE.eco
mlp_sh.eco = MLP_SH_ASE.eco

comb_sh = ensemble_SH_ASE 
comb_lh = ensemble_LH_ASE

comb_sh.eco = ensemble_SH_ASE.eco
comb_lh.eco = ensemble_LH_ASE.eco

  
# Create a data frame to store the model names and their ASE scores
model_ase_df <- data.frame(Model = 
                             c("AR(7)MA(2) Univariate Short Model", "AR(7)MA(2) Univariate Short Model Eco", 
                               "AR(7)MA(2) Univariate Long Model", "AR(7)MA(2) Univariate Long Model Eco",
                               "AR(0)MA(0) Univariate Short Model", "AR(0)MA(0) Univariate Short Model Eco", 
                               "AR(0)MA(0) Univariate Long Model", "AR(0)MA(0) Univariate Long Model Eco", 
                               "Rolling Window RMSE Short Model", 
                               "Rolling Window RMSE Long Model", 
                               "VAR Short Horizon", "VAR Short Horizon Eco", 
                               "MLP Short Horizon", "MLP Short Horizon Eco", 
                               "Ensemble Model Short Horizon", "Ensemble Model Short Horizon Eco",
                               "VAR Long Horizon", "VAR Long Horizon Eco", 
                               "MLP Long Horizon", "MLP Long Horizon Eco", 
                               "Ensemble Model Long Horizon", "Ensemble Model Long Horizon Eco"),
                           ASE = c(aic_uni_sh, aic_uni_sh.eco, 
                                   aic_uni_lh, aic_uni_lh.eco, 
                                   bic_uni_sh, bic_uni_sh.eco, 
                                   bic_uni_lh, bic_uni_lh.eco, 
                                   roll_win_ase_short, 
                                   roll_win_ase_long, 
                                   var_sh, var_sh.eco, 
                                   mlp_sh, mlp_sh.eco,
                                   comb_sh, comb_sh.eco, 
                                   var_lh, var_lh.eco, 
                                   mlp_lh, mlp_lh.eco, 
                                   comb_lh, comb_lh.eco))


# Round the ASE scores to 4 decimal places
model_ase_df$ASE <- round(model_ase_df$ASE, 4)


#Add a new Column "Rank" to the DF which contains there rank order
model_ase_df$Rank <- rank(model_ase_df$ASE)
model_ase_df <- model_ase_df [order(model_ase_df$Rank), ]

# Display the data frame in an output box
print(model_ase_df)  
##                                    Model    ASE Rank
## 11                     VAR Short Horizon 0.0670  1.0
## 8   AR(0)MA(0) Univariate Long Model Eco 0.0859  2.0
## 21           Ensemble Model Long Horizon 0.0939  3.0
## 15          Ensemble Model Short Horizon 0.1000  4.0
## 20                  MLP Long Horizon Eco 0.1066  5.0
## 19                      MLP Long Horizon 0.1140  6.0
## 17                      VAR Long Horizon 0.1551  7.0
## 7       AR(0)MA(0) Univariate Long Model 0.1621  8.5
## 22       Ensemble Model Long Horizon Eco 0.1621  8.5
## 18                  VAR Long Horizon Eco 0.1642 10.0
## 3       AR(7)MA(2) Univariate Long Model 0.1671 11.5
## 4   AR(7)MA(2) Univariate Long Model Eco 0.1671 11.5
## 16      Ensemble Model Short Horizon Eco 0.1944 13.0
## 12                 VAR Short Horizon Eco 0.2019 14.0
## 14                 MLP Short Horizon Eco 0.2295 15.0
## 13                     MLP Short Horizon 0.2497 16.0
## 6  AR(0)MA(0) Univariate Short Model Eco 0.3069 17.0
## 1      AR(7)MA(2) Univariate Short Model 0.3818 18.5
## 2  AR(7)MA(2) Univariate Short Model Eco 0.3818 18.5
## 5      AR(0)MA(0) Univariate Short Model 0.3892 20.0
## 9        Rolling Window RMSE Short Model 0.4590 21.0
## 10        Rolling Window RMSE Long Model 0.5880 22.0

6. Provide the forecasts and prediction limits for both the short and long term forecasts.

# Fit the univariate forecasts AIC & BIC Short Horizions

# AIC Model Forecast
aic_fore.short = fore.arima.wge(ts_nly_open, phi = aic_est$phi, theta = aic_est$theta, d=1,n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

aic_fore.short.eco = fore.arima.wge(ts_nly_open.eco, 
                                    phi = aic_est.eco$phi, 
                                    theta = aic_est.eco$theta, d=1,n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# BIC Model FOrecast
bic_fore.short = fore.arima.wge(ts_nly_open, phi = bic_est$phi, theta = bic_est$theta, d=1, n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

bic_fore.short.eco = fore.arima.wge(ts_nly_open.eco, 
                                    phi = bic_est.eco$phi, 
                                    theta = bic_est.eco$theta, d=1, n.ahead = 12, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# Both are more or less the same model given the ARMA component cancel each other out 

# Fit the AIC/BIC Picks for Long Horizons

# AIC Model Forecast
aic_fore.long = fore.arima.wge(ts_nly_open, phi = aic_est$phi, theta = aic_est$theta, d=1,n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

aic_fore.long.eco = fore.arima.wge(ts_nly_open.eco, 
                                   phi = aic_est.eco$phi, 
                                   theta = aic_est.eco$theta, 
                                   d=1,n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# BIC Model FOrecast
bic_fore.long = fore.arima.wge(ts_nly_open, phi = bic_est$phi, theta = bic_est$theta, d=1, n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04 -0.04

bic_fore.long.eco = fore.arima.wge(ts_nly_open.eco, 
                                   phi = bic_est.eco$phi, 
                                   theta = bic_est.eco$theta, 
                                   d=1, n.ahead = 20, lastn = T, limits = T)
## y.arma -0.02 -0.48 0.24 0.17 -0.29 0.21 0.22 -0.04 0.32 0.26 0.14 -0.14 -0.02 0.42 -0.2 0.36 0.09 -0.52 0.09 0.43 -0.19 0.28 0.03 0.05 0.08 0.09 0.02 -0.17 0 0.03 -0.22 -0.37 0.08 0.1 0.08 -0.08 0.19 0.33 0.02 0.12 -0.1 -0.43 -0.04 -0.44 -0.11 0.41 -0.01 0.16 0.04 -0.15 0.16 0.11 0.01 -0.07 -0.03 -0.08 -0.3 -0.06 -0.18 -0.18 -0.07 -0.01 -0.04 0.14 0.08 -0.1 -0.19 0.04 0.27 -0.21 -0.08 -0.06 -0.09 -0.07 -0.13 -0.03 0.08 0.1 0.2 -0.52 -0.01 0.01 -0.67 0.06 0.18 0.28 -0.22 0.4 0.13 0.29 -0.51 0.3 0.03 -0.09 0.27 -0.29 -0.09 0.24 -0.1 0.07 -0.26 -0.48 0.1 -0.02 0.12 -0.19 -0.27 0.31 0.24 -0.44 0.06 -0.41 0.06 0.46 0.22 0.06 0.2 0.23 0.1 -0.01 0.12 0.04 -0.12 -0.17 0.24 -0.17 0.2 0.45 0.15 -0.07 -0.34 0.21 -0.03 -0.2 0.31 0.05 -0.17 -0.14 0.25 0.08 0.11 -0.03 -0.13 -0.13 0.1 -0.49 0.06 0.32 -0.32 -0.42 0.1 -0.04 0.17 0.07 -0.25 -0.07 0.08 -0.13 0.49 -0.25 0.11 -0.31 0.24 -0.11 0.01 0.09 0.06 0.24 0.3 0.23 -0.12 0 0.06 0.12 -0.03 0.19 0.33 0.15 0.06 -0.26 -0.28 0.23 0.28 0.21 0.11 0.26 0.22 -0.56 0.02 0.26 -0.42 0.06 0.04 0.3 0.06 0.01 0.09 -0.07 -0.05 0.12 -0.26 -0.06 0.09 0.02 -0.67 -0.39 0.01 0.29 0.29 0.06 0.12 0.29 -0.2 -0.17 -0.32 -0.26 -0.08 -0.35 -0.56 -0.09 0.38 -0.18 -0.33 0.25 0.27 -0.06 -0.16 0.1 -0.19 -0.03 0.21 -0.13 0.06 0.01 0 0.07 0.05 -0.08 0.16 -0.33 0.24 -0.12 0.07 0.09 -0.03 -0.13 0.27 -0.07 0.04 -0.06 -0.35 0.07 -0.11 -0.11 -0.21 0.07 -0.09 -0.11 0.27 -0.04

# Fit the VAR model using the lagged_data Short

plot(data$Open, type = "l", main = "Forecast of VAR Model Short Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(251,262,1),pred.short$fcst$Open[,1],col = "red")

plot(data.eco$Open, type = "l", main = "Forecast of VAR Eco Model Short Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(250,261,1),pred.short.eco$fcst$Open[,1],col = "green")

plot(data$Open, type = "l", main = "Forecast of VAR Model Long Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(243,262,1),pred.long$fcst$Open[,1],col = "red")

plot(data.eco$Open, type = "l", main = "Forecast of VAR Eco Model Long Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(242,261,1),pred.long.eco$fcst$Open[,1],col = "green")

# Forecast the MLP model Short
plot(df.adj$Open, type = "l", main = "Forecast of MLP Model Short Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(251,262,1),fore.mlp.short$mean,col = "blue")

plot(finaldata$Open, type = "l", main = "Forecast of MLP Eco Model Short Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(250,261,1),fore.mlp.short.eco$mean,col = "green")

plot(df.adj$Open, type = "l", main = "Forecast of MLP Model Long Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(243,262,1),fore.mlp.long$mean,col = "blue")

plot(finaldata$Open, type = "l", main = "Forecast of MLP Eco Model Long Horizon Market Open Price at lag 1", cex.main = 0.8)
lines(seq(242,261,1),fore.mlp.long.eco$mean,col = "green")

# Forecast the Ensemble Models
plot(df.adj$Open, type = "l", main = "Forecast of Ensemble Short Horizon Model for Market Open Price at lag 1", cex.main = 0.8)
lines(seq(251,262,1),sh_ensemble,col = "pink")

plot(finaldata$Open, type = "l", main = "Forecast of Ensemble Eco Short Horizon Model for Market Open Price at lag 1", cex.main = 0.8)
lines(seq(250,261,1),sh_ensemble.eco,col = "green")

plot(df.adj$Open, type = "l", main = "Forecast of Ensemble Long Horizon Model for Market Open Price at lag 1", cex.main = 0.8)
lines(seq(243,262,1),lh_ensemble,col = "pink")

plot(finaldata$Open, type = "l", main = "Forecast of Ensemble Eco Long Horizon Model for Market Open Price at lag 1", cex.main = 0.8)
lines(seq(242,261,1),lh_ensemble.eco,col = "green")

rmarkdown::render(“C:/Users/19405/OneDrive/Documents/MSDS/Time Series/Robert_(Reuven)_Derner_TS_Summer_Project_2023_Final.Rmd”, output_file = “output.html”)